DEV Community


JavaScript Interview Questions

fariha profile image Farihaakter ・3 min read

1. Truthy and Falsy value:

JavaScript has truthy and falsy value. They are called boolean in JS. When the value of a variables in javascript is null, 0, undefined, NaN, false, -0, then this values are called falsy.
Again when the value of a variable is true, {}, [], " ", 12 are all truthy value.

2.Null vs Undefined:

Null is an empty value while undefined is a variable that is declared but never assigned a value. When a variable is declared but no value is assigned to it then it returns undefined when called.

let a;
// gives undefined in return

let a = null;
// null
Enter fullscreen mode Exit fullscreen mode

3. Double-Equal and Triple-Equal:

Both double equal and triple equal is used in JS. Both are value comparison operation in JS.
The double equal compares the values of two variables after converting them to a common type. It does not compare the type of the values. Example:

console.log(2 == '2')
// will return true
Enter fullscreen mode Exit fullscreen mode

While triple equal compares both the type and the value of a variables. If the values are not the same type then the values are considered unequal.

console.log(2 === 2)
// will return true
Enter fullscreen mode Exit fullscreen mode

4. Global scope and Block scope:

In JavaScript, scope determines the accessibility of a variable.
javascript has two types of scope:

Global scope

Local scope

Variables that are declared inside a function are only accessible from that function it is defined. They are local or block scope variables in JS.
On the other hand the variables that are defined outside of a function are became GLOBAL variables. They are accessible from anywhere.

5. Bind, Call, Apply:

Bind method creates a new function when called. It takes the function property of an object and bind it to the new object. So the new object can execute the code inside of that function.

Call method can be used to get a method of another object. Example:

var person = {
fullName: function() {
return this.firstName + " " + this.lastName;

var person1 = {
lastName: "Aktar"
};  // Will return "Fariha Aktar"
Enter fullscreen mode Exit fullscreen mode

apply method is similar to call method. The apply method takes arguments as an array. apply nmethod is used when you want to use arguments as an array.

6.setTimeout, setInterval:

setTimeout() methods calls a function after a specific number of millisecond.
setInterval() is similar to setTimeout(). setInterval is used when you want to repeat the execution method of a function.

{ alert("Hello World");
}, 2000);
Enter fullscreen mode Exit fullscreen mode

7. What is JavaScript:

JavaScript is a high level programming language that is used in modern web pages. It is used for both client and server side website. Most of the websites are build with JS in this modern age. It supports event-driven, functional, object-oriented, and prototype-based programming styles.

8. Features of JS:

The main features of JS is given below:

DOM manipulation:

The most amazing features of JS is DOM manipulation. In the early years DOM were static. but after javascript DOM became dynamic.

Functions as first class object:

In JS, functions are used as objects. It can have methods and properties just like any other objects. It also can pass as an arguments to another function.

JavaScript as a Client-Side Language:

JS can be used as a client side language. Developers don't have to learn any other language for server side.

The Syntax is Similar to Java:

JavaScript has similar syntax as java. It makes things easier for developers to work with JS.

9. How javascript code executes:

Javascript code is executed in two phases.

Memory creation:

In this phase, JS allocates all the variables and functions in a program.

Code execution phase:

In this phase, JS first executes main. then Js runs the code line by line

10.What is DOM :

DOM represent a page in a web. Programmers can manipulate its structure, style and content. A web page is a document. This document can be displayed in a web browser or as the HTML source.
The DOM represents that same document.

Discussion (0)

Forem Open with the Forem app