Javascript interview preparation cheat sheet
Hi folks, today I will be covering few topics which are mostly asked in interview...
1. Scope
The scope manages the availability of variables or we can also say that it determines the accessibility of variables.
Types of Scopes in JavaScript:
- Block Scope
- Function scope
- Local scope
- Global scope
Block Scope
Variables that are declared inside a { } block cannot be accessed from outside the block. Earlier JavaScript has only two scope function scope and global scope. Let and const are two important keywords that were introduced by ES6 and these two provides block scope in JavaScript.
Function scope
Variables defined inside a function are not accessible from outside the function and variables declared with var, let and const are quite similar when declared inside a function.
Local scope
Local variables have Function Scope which means that they can only be accessed from within the function.
Global scope
Variables declared Globally (outside of any function) have Global Scope and Global variables can be accessed from anywhere in a program. Similar to function scope variables declared with var, let and const are quite similar when declared outside a block.
2. Single Thread
JavaScript is a single-threaded language because while running code on a single thread, it can be really easy to implement as we don’t have to deal with the complicated scenarios that arise in the multi-threaded environment.
It executes the code line by line.