-
JavaScript Code Runs inside Execution Context
- Execution Context
Global Execution context intialized everytime js promgram runs
- Memory (Variable Environment)
- Vairables
- Functions
- key:value
eg: varName : 10; funcName :{console }
- key:value
- Code (Thread of Execution)
- Memory (Variable Environment)
- Execution Context
Global Execution context intialized everytime js promgram runs
-
JavaScript is a synchronous single-threaded language
-
Memory Phase (Creating memory for variables and function)
- default:
varName is assigned as undefined
funcName is assigned to function code
- eg : varName:undefined funcNaame:{...}
- default:
varName is assigned as undefined
funcName is assigned to function code
-
Code Execution Phase
- For each function call new Execution Context is created
-
-
CALL STACK (Controls order of Execution)
- Each Execution context created will put into stack
- By Default Global Execution Context is already inside
- Once all the code is executed all the context is deleted from the Stack
-
HOISTING - functions to be safely used in code before they are declared
- Functions declared using function keyword can be accessed anywhere (before/after declaration)
- Arrow functions acts a variable and wont copy the function code in Execution context memory
- Arrow functions called before initializations will be undefined
-
SCOPE
- Accessing variable within the block.
- Lexical Memory( In Hirarchy) - Local Memory along with Parent
-
LET & CONST
- Let & Const variables are stored in seperate memory space other than global memory space
- Accessing let & const before initialization will throws an error but incase of var it prints undefined
- Temporal Dead zone is between ,let & const are assigned with a memory space and not assigned any value to them
- Reference Error occurs when we try to access let & const variable before initializing the value i.e variable in Temporal Dead Zone
- var variables can be redeclared but incase of let and const variables cannot be reintialized
* Move all the let & const declaration to top of the program so that we can minimize window of temporal dead zone * Try to declare variables using const -> let -> var (worst case)
-
ERRORS
- SyntaxError
- Error in syntax throws syntax error
- eg: misspelled keywords,duplicate declaration
- Error in syntax throws syntax error
- TypeError
- Errors occurs while the operation cannot be performed
- eg:reintializing const variable with another value;
- Errors occurs while the operation cannot be performed
- ReferenceError
- Trying to access variables that we cannot access it
- eg:accessing variable that was not declared, variable with let & const type cannot be accessed before intialization
- Trying to access variables that we cannot access it
- SyntaxError
-
Block
- Blocks defined between a curly braces i.e {} its used to group multiple statement
- It is called as Compound Statement
- let & const are block scoped i.e cannot be accessed outside the block
-
Closure
- Function along with lexical scope forms a closure Eg: function x(){ let a = 5; function y(){ console.log(a) } y(); } x();
- Uses of Closures
- Module Design Pattern
- Currying
- Functions like once (function that can be exactly one time)
- memoize
- maintaining state in async
- setTimeouts
- Iterators
- and many more...
-
Notifications
You must be signed in to change notification settings - Fork 0
dhachanamoorthy/JavaScript
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Understanding JavaScript Functionality
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published