Javascript Interview questions and answers

In this article, we will cover javascript interview questions for beginners. So let's start it.

Javascript Interview questions and answers

1. What is javascript?

Javascript is a scripting language with the OOPs( object-oriented language ) capability. It is used to create dynamic web pages but nowadays javascript is also used as a server-side scripting language.  

2. List of javascript data types.

1. Undefined

2. Null

3. Symbol

4. String

5. Object

6. Number

7. Boolean

3. How to add javascript in an HTML file?

We use a script tag to add a javascript file in an HTML file.

for example:- 

<script src="filename.js"></script>

4. What is the use of the typeof operator?

To check the type of variable in javascript we use the typeof operator.

5. Difference between null and undefined in javascript.

Null: The value of the variable is purposely absent.

undefined: the value of the variable does not exist in Program.

6. What is the use of isNaN?

isNaN( is Not a Number ) is used to check whether a value is a number or not. If the value is a number then it returns false otherwise it returns true.

7. How we can create an object in JavaScript?

To define an object in javascript we have different kinds of ways but here we use an object literal.

let obj={

    name: "Hjack",


8. Disadvantages of using javascript?

Client-side Javascript does not allow us to read or write data in files. Because of security reasons. Also, Javascript doesn't support multithreading.

9. How do we read arrays elements?

To read an array element we have to know its length. But in javascript, we have a built-in property called length to know arrays length.

var a=[1,2,3,4,5];

for(var i=0;i<a.length;i++){



10. How we can define anonymous functions?

Anonymous functions the same as a normal function but it would not have any name.


var a=function(){



11. What is the "this" keyword in javascript?

Javascript is more famous for the "this" keyword. "this" keyword refers to the object where it was defined.  

12. What is the difference between == and === operator?

== operator compare the value of two operands but === operator compares the value as well as the type of operands.

13. How we can add CSS in HTML elements using javascript?

To add CSS in HTML elements we use style property. Using it we can manipulate CSS.

for example:-


14. What is BOM?

BOM stands for Browser Object Model. Using it we can interact with Browser.

15. What is DOM?

DOM stands for Document Object Model. Using it we can manipulate HTML files.

16. What is Closure?

In javascript, Clouser is created whenever a variable is defined outside the current function scope but it can access by the current function.

for example:- 

var a=5;

function add(){

   return (5+10);



17. What is a Higher-order function in javascript?

A higher-order function is work as a simple function but it takes another function as an argument

 for example:-

function HOF( fun ){




console.log("Hello HOF")


18. What is a callback?

A Callback is a function that will be executed after the main function 

for example:-

function add(sum){



function main(a,b,add){





19.  What is Hoisting?

Hoisting is the default behavior of javascript where all the function and variable declarations are moved on top.

For example:-



var sum;

20. How we can define the arrow function?

var a=(b,c)=>{




Post a Comment