Crystal-Clear-Javascript
Javascript
First what do you mean 'Javascript'
In simple words 'Every thing is javascript happen inside an Execution Context and it is lightweight,interpreted(means "it will execute the code line wise ") programming language.'
javascript is client slide scripted language
javascript is most popular language now day,
Why Study Javascript?
- Javascript is used in web-development and extend to mobile app development ,desktop app development and game development
- Every thing in javascript comes installed on every modern web browser('like :google chrome,safari) and not need any environment setup
Let the terms of javascript :
- Execution Context(the environment in which our code is executed and is evaluted)
- Execution Stack
- variable object
- scope chain
- 'this' variable
Execution Stack
Execution stack also known as 'calling stack' is a stack follow 'LIFO'(last in first out) Structure
which is used to store all the execution context created during the code execution
Variable object
For each function (function declaration ) a property is created in the varible object .which is pointing to that function
for each varible (variable declaration ) a property is created in the variable object which is the set to undefined
Hoisting is a javascript mechanism where variable and function declarations are moved to the top of
their scope before the code execution
Function Hoisting
Before the execution phase every variable and funtion moved to top of their global scope and set variable value to 'undefined ' and in case of function it store the all function definition
CODE:
console.log(fun())
console.log(x)
var x=10
function fun(){
console.log('printing function')
}
OUT-PUT on Browser:
- undefined
- f fun(){`
console.log('printing function')
}
Lexical Environment :
it's the internal js engine construct that holds identifier-variable mapping. (here identifier refers to the name of variables/functions, and variable is the reference to actual object [including function type object] or primitive value). A lexical environment also holds a reference to a parent lexical environment.
In simple words (local memory + parent lexical Environment ) this both shows the lexical environment of current execution context
And every lexical environment tracks its parent lexical environment (that of parent execution context)
As a result, every function has a chain of lexical environments attached to it.
Scope : it's the language agnostic concept, to refer to the visibility of variables or functions to the executing code.
In js a variable or function is visible to the executing code, if it is there in the current lexical environment or in the lexical-environment-chain of the enclosing function. In case of global code, the chain does not exist.
Regarding Let and Const
'Let' and 'Const' declarations are both block-scoped, which means they are only accessible within the {
}
surrounding them "var', on the other hand, doesn't have this restriction.
TEMPORAL DEAD ZONE
This term is describing the state where variables are un-reachable. They are in scope, but they aren't declared.
Temporal dead zone : time between the initiation of variable and assigning value to variable is known as temporal dead zone
CODE:
1:{ console.log(money)// This is the temporal dead zone for the money variable
let money= 25 ; // now temporal dead zone no more
console.log(money)
}
2:{ console.log(a)
let a=12; /// we can't use same name of variable name with once it is defined to 'let '
var a=12;
}
Here you can find Reference error in both the cases
0 comments:
Post a Comment