Js 2
Js 2
learndepth.com/InterviewQa/"JavascriptInt"
let a;
a = 0;
console.log(a) // 0
a = "Hello"
console.log(a) // "Hello"
Primitive datatypes:
String
number
boolean
undefined
Bigint
symbol
Non-Primitive datatypes:
Array
Object
Date
👉
not be any error. This is called hoisting.
😉
Interview Tip: Mention buzz word 'temporal dead zone' for let & const in above
answer so that interviewer will ask What is temporal dead zone.
1/4
Function declarations: Fully hoisted.
var - Hoisted
Arrow functions: Not hoisted
Anonymous Function expressions: Not hoisted
let and const - Hoisted but not initialized. (Temporal dead zone).
class declarations - Hoisted but not initialized.
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.
Any attempt to access them result in reference errors.
function somemethod() {
console.log(counter1); // undefined
console.log(counter2); // ReferenceError
var counter1 = 1;
let counter2 = 2;
}
Q6. What are the differences let, var and const ? (Most asked)
Scope:
Variables declared with var are function scoped.( available through out the function
where its declared ) or global scoped( if defined outside the function ).
Variables declared with let and const are block scoped.
Reassignment:
Arrow functions
Let and Const declarations.
Destructuring assignment
Default parameters
Template literals
Spread and Rest operators
2/4
Promises
Classes
Modules
👉
Map, Set, Weakmap, Weakset
😉
Interview Tip: Here try to explain definations (provided in below questions) for
these features so that you can kill 2-3 min of interview time
Arrow functions are introduced in ES6. They are simple and shorter way to write
functions in javascript.
👉
Arrow functions cannot be used as generator functions.
Note: Arrow functions + this combination questions will be asked here. Please
explore on this combinations.
Spread operator is used to spread or expand the elements of an iterable like array
or string into individual elements.
Uses:
Concatenating arrays.
let x = [1,2];
let y = [3,4];
3/4
function createExample(arg1,arg2){
console.log(arg1,arg2);
}
createExample(…a)
👉 Interview Tip: Practice the above examples mentioned and showcase them in
interviews to make interviewer think that you are a practical person. 😉
Rest operator is used to condense multiple elements into single array or object.
This is useful when we dont know how many parameters a function may receive
and you want to capture all of them as an array.
function Example(...args){
console.log(args)
}
Example(1,2,3,4);
4/4