JavaScript Interview Questions

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 …


This content originally appeared on DEV Community and was authored by Farihaakter

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;
console.log(a);
// gives undefined in return

let a = null;
console.log(a);
// null

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

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

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 = {
firstName:"Fariha",
lastName: "Aktar"
}

person.fullName.call(person1);  // Will return "Fariha Aktar"

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.

setTimeout(function()
{ alert("Hello World");
}, 2000);

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.


This content originally appeared on DEV Community and was authored by Farihaakter


Print Share Comment Cite Upload Translate Updates
APA

Farihaakter | Sciencx (2021-05-08T17:46:18+00:00) JavaScript Interview Questions. Retrieved from https://www.scien.cx/2021/05/08/javascript-interview-questions/

MLA
" » JavaScript Interview Questions." Farihaakter | Sciencx - Saturday May 8, 2021, https://www.scien.cx/2021/05/08/javascript-interview-questions/
HARVARD
Farihaakter | Sciencx Saturday May 8, 2021 » JavaScript Interview Questions., viewed ,<https://www.scien.cx/2021/05/08/javascript-interview-questions/>
VANCOUVER
Farihaakter | Sciencx - » JavaScript Interview Questions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/08/javascript-interview-questions/
CHICAGO
" » JavaScript Interview Questions." Farihaakter | Sciencx - Accessed . https://www.scien.cx/2021/05/08/javascript-interview-questions/
IEEE
" » JavaScript Interview Questions." Farihaakter | Sciencx [Online]. Available: https://www.scien.cx/2021/05/08/javascript-interview-questions/. [Accessed: ]
rf:citation
» JavaScript Interview Questions | Farihaakter | Sciencx | https://www.scien.cx/2021/05/08/javascript-interview-questions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.