Skip to content

Commit b45c92e

Browse files
authored
Update README.md
1 parent e53900f commit b45c92e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
1. [Is JavaScript a dynamically typed language or a statically typed language?](#q1-is-javascript-a-dynamically-typed-language-or-a-statically-typed-language)
55
2. [What are the different datatypes in JavaScript?](#q2-what-are-the-different-datatypes-in-javascript-most-asked)
66
3. [What is Hoisting in JavaScript?](#q3-what-is-hoisting-in-javascript-most-asked)
7+
4. [What is Temporal Dead Zone?](#q4-what-is-temporal-dead-zone)
8+
5. [What are the differences between `let`, `var`, and `const`?](#q5-differences-between-let-var-and-const)
79

10+
811
### Q1. Is JavaScript a dynamically typed language or a statically typed language?
912
JavaScript is a dynamically typed language. It means all type checks are done at runtime (when the program is executing). So, we can just assign anything to the variable and it works fine.
1013

@@ -40,5 +43,40 @@ console.log(a); // "Hello";
4043
- In other scripting/server side languages, variables or functions must be declared before using it.
4144
- In javascript, variables and functions can be used before declaring it. The javascript compiler moves all the declarations of variables and functions on top. so there will not be any error. This is called hoisting.
4245
#### 👉 Interview Tip: Mention buzz word 'temporal dead zone' for let & const in above answer so that interviewer will ask What is temporal dead zone. 😉
46+
### What are the various things hoisted in javascript ?
47+
- Function declarations: Fully hoisted.
48+
- var - Hoisted
49+
- Arrow functions: Not hoisted
50+
- Anonymous Function expressions: Not hoisted
51+
- let and const - Hoisted but not initialized. (Temporal dead zone).
52+
- class declarations - Hoisted but not initialized.
53+
##
54+
[Back to Top](#javascript-basics)
55+
56+
### Q4. What is temporal dead zone ?
57+
- It is a specific time period in the execution of javascript code where the variables declared with let and const exists but cannot be accessed until the value is assigned.
58+
- Any attempt to access them result in reference errors.
59+
```
60+
function somemethod() {
61+
console.log(counter1); // undefined
62+
console.log(counter2); // ReferenceError
63+
var counter1 = 1;
64+
let counter2 = 2;
65+
}
66+
```
67+
##
68+
[Back to Top](#javascript-basics)
69+
70+
### Q5. What are the differences let, var and const ? (Most asked)
71+
** Scope: **
72+
- Variables declared with var are function scoped.( available through out the function where its declared ) or global scoped( if defined outside the function ).
73+
- Variables declared with let and const are block scoped.
74+
** Reassignment: **
75+
- var and let can be reassigned.
76+
- const cannot be reassigned.
77+
** Hoisting: **
78+
- var gets hoisted and initialized with undefined.
79+
- let and const - gets hoisted to the top of the scope but does not get assigned any value.(temporal dead zone)
80+
4381
##
4482
[Back to Top](#javascript-basics)

0 commit comments

Comments
 (0)