0% found this document useful (0 votes)
4K views

Js 2

Uploaded by

sivajikondeti40
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views

Js 2

Uploaded by

sivajikondeti40
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Learn Depth

learndepth.com/InterviewQa/"JavascriptInt"

Q1. Is javascript a dynamically typed language or a statically typed language ?

Javascript is a dynamically typed language.


It means all type checks are done at run time ( When program is executing )
So, we can just assign anything to the variable and it works fine.

let a;
a = 0;
console.log(a) // 0
a = "Hello"
console.log(a) // "Hello"

Q2. What are the different datatypes in javascript ? (Most asked)

Primitive datatypes:

String
number
boolean
undefined
Bigint
symbol
Non-Primitive datatypes:

Array
Object
Date

Q3. What is Hoisting in javascript ? (Most asked)

In other scripting/server side languages, variables or functions must be declared


before using it.
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.

😉
Interview Tip: Mention buzz word 'temporal dead zone' for let & const in above
answer so that interviewer will ask What is temporal dead zone.

Q4. What are the various things hoisted in javascript ?

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.

Good Reference: https://stackabuse.com/hoisting-in-javascript/


Q5. What is temporal dead zone ?

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:

var and let can be reassigned.


const cannot be reassigned.
Hoisting:

var gets hoisted and initialized with undefined.


let and const - gets hoisted to the top of the scope but does not get assigned any
value.(temporal dead zone)

Q7. List out some key features of ES6 ? (Most asked)

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

Q8. What are limitations of arrow functions in javascript ?

Arrow functions are introduced in ES6. They are simple and shorter way to write
functions in javascript.

Arrow functions cannot be accessed before initialization


Arrow function does not have access to arguments object
Arrow function does not have their own this. Instead, they inherit this from the
surrounding code at the time the function is defined.
Arrow functions cannot be used as constructors. Using them with the 𝙣𝙚𝙬 keyword
to create instances throws a TypeError.

👉
Arrow functions cannot be used as generator functions.
Note: Arrow functions + this combination questions will be asked here. Please
explore on this combinations.

Q9. What’s the spread operator in javascript ?

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];

let z = […x,…y] ⇒⇒ 1,2,3,4

Copying arrays or objects.

let a = […x] // 1,2

Passing array of values as individual arguments to a function.

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. 😉

Q10. What is rest operator in javascript ?

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

You might also like