Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Execution context
- //javascript scope
- //javascript closure
- //javascript hoisting
- //Visualization (all)
- //Execution context
- //global (outside of function)
- //functional (inside of a function)
- /////////// global
- // const num1 = 10
- // const num2 = 20
- // functional execution context
- // function add(){
- // return num1 + num2
- // }
- // console.log(add())
- // /// functional execution context
- // function subtract(){
- // return num1 - num2
- // }
- // console.log(subtract())
- // /////
- //scope
- //global scope (outside of function)
- //functional scope (var)
- //block scope(ES6) enclosed by {}
- //global
- // const a = 10
- //block scope ( applicable for let, const)
- // if(true){
- // var d = 20
- // const c = 30
- // }
- // console.log(d)
- // // console.log(c)
- // function sum (){
- // //local
- // const b = 10
- // var e = 20
- // // console.log(f)
- // function inner(){
- // const a = 100
- // console.log(a)
- // const f = 20
- // }
- // inner()
- // console.log(a)
- // }
- //not accessible (local scope)
- // console.log(e)
- // sum()
- //closure scope
- // function greet(greetings){
- // //greetings = 'hello'
- // return name =>{
- // //name = 'samim'
- // return greetings + ' ' + name
- // }
- // }
- // const secondFn = greet('hello')
- // console.log(secondFn('samim'))
- // console.log(secondFn('samim'))
- //javascript hoisting
- // console.log(a) //temporal dead zone
- // console.log(x)
- // console.log(sum(10, 20))
- // console.log(subtract(20, 10))
- // const a = 10
- // var x = 20
- // function sum(num1, num2){
- // return num1 + num2
- // }
- // console.log(sum(10, 20))
- // var subtract = function (num1, num2){
- // return num1 - num2
- // }
- // console.log(subtract(20, 10))
- // console.log(a)
- //Hoisting
- //creation stage
- //variable declaration
- //take function statement in memory
- //execution stage
- //variable value assignment
- //calling (run)
- //creation stage
- // var x;
- // var a;
- // function sum(num1, num2){
- // return num1 + num2
- // }
- // var subtract;
- // //execution stage
- // console.log(a)
- // console.log(x)
- // console.log(sum(10, 20))
- // console.log(subtract(20, 10))
- // var a = 10
- // var x = 20
- // a = 10
- // x = 20
- // subtract = function (num1, num2){
- // return num1 - num2
- // }
- // console.log(subtract(20, 10))
- // console.log(a)
- //var let const
- //var- attached with window, re-declaration, Hoisting, functional scope
- //let - Not attached with window, No hoisting(?), no re-declaration but can be re-assigned can be block scope
- //const - same as let, can't be re-assigned
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement