Question 1: What is the difference between declaring variables using let, var, and const?
The var, let, and const all are used to declare variables; but the scope of the variables declared with let and const is restricted to the block (A set of curly braces defines a block of code), whereas the variables declared with var are scoped globally. Here’s an example that shows the scope of the variables:
var a = 1;
let b = 2;
// b is undefined outside of the block as it was declared using let
var a = 1;
const c = 3;
// Similarly, c is also undefined outside of the block
Another difference between var and let is that the variables created with var can be redeclared and redefined, whereas the variables created with the let keyword can only be redefined. Variables declared with the let keyword can also be redeclared in different blocks.
The variables declared with the const are block-scoped, and their values cannot be changed. They cannot be redefined or redeclared and have to be initialized during declaration.
Question 2: Differentiate between “=”, “==” and “===” operators?
The = is an assignment operator and is used to set the value of a variable. The == operator is used to compare the value of two variables, whereas the === operator compares the values and the types of two variables. The == operator will return true if we compare ‘1’(string) with 1(integer), whereas the === operator will return it as false:
‘1’ === 1
if (‘1’ == 1)
if (‘1’ === 1)
Question 3: Difference between “undefined” and “null”?
- By using the dot “.” operator
- By using the square brackets syntax
user.age = 33;
user[‘id’] = 05;
Question 5: What is the difference between a statically and dynamically typed language?
Statically typed languages require you to define the variable’s data type while declaring it, whereas there is no such restriction in dynamically typed language. The dynamically typed languages perform type checks at runtime, whereas the statically typed programming languages perform tasks simultaneously.
A variable can be used to store any data type in a dynamically typed language, while in a static language, a variable can only store one data type.
Question 7: Difference between pop(), push() and shift(), unshift() methods
The pop() and push() methods are used to remove and add an element/item at the ending point of an array respectively. Whereas the shift() and unshift() methods are used to remove and add elements/elements from the start point of an array:
intArr.pop(); // returns the removed item
intArr.push(67); // returns the new array length
intArr.shift(); // returns the removed item
intArr.unshift(23); // returns the new array length
Question 8: What is the “this” keyword
Question 10: What will the following code return:
The code is given above returns “string.” It can be divided into two different pieces:
- typeof 10
- The type of the returned value of typeof 10
Question 12: What are cookies?
Cookies are text files that store the information of the user at the time of browsing. They preserve the state of the user. Cookies are used to remember the user’s information each time the user sends a new request to the server.
Question 15: What is closure?
var two = 2;
var three = 3;
console.log(one + two + three);
Question 17. What is the datatype of an array?
Using the typeof() operator over an array element will show the variable as an object.
However, if you really want to know whether a variable is an array or object, you can use Array.isArray() method:
The map() function is used when we need to iterate through the whole array and change the values of each element of an array.
For example, if we have a list of numbers and we want to add 5 to each number:
Question 20: What will be the output of 30+50+“20”?
The output of the given expression will be 8020.
Since 30 and 50 are integers, they will be added as integers, and the answer will be 80. Later, “20” is a string, so 80 will be concatenated with “20,” and the final result will be “8020”.
Applying for a new job and going through an interview can feel like an overwhelming task and can cause great anxiety, but you need to trust yourself.