Javascript Interview Questions

Table of Contents

JavaScript is a powerful PC programming language. It is lightweight and most regularly utilized as a piece of site pages, whose usage permits customer side content to communicate with the client and make dynamic pages. It is a deciphered programming language with object-arranged abilities. The main role of JavaScript is to give a superior encounter to the client. It controls the articles inside the HTML archive.

Development History of Javascript

JavaScript was made by Brendan Eich in 1995 during his time at Netscape Communications. A wide range of dialects affected the linguistic structure and structure of JavaScript. JavaScript is one of the most adaptable dialects at any point made. Nonetheless, JavaScript is one of those dialects that individuals guarantee to know, however, they definitely have no clue how complex JavaScript can get.

It enables you to execute complex things on site pages — each time a site page accomplishes something beyond stay there and show static data for you to take a gander at — showing convenient substance refreshes, intelligent maps, energized 2D/3D designs, looking over video jukeboxes, and so on — you can wager that JavaScript is presumably included.

Latest Version

The most recent JavaScript rendition was 1.8.5. (Identical to ECMAScript 5).
The most significant thing that should be possible by the employments of JavaScript is building applications without web settings. Mobiles being for the most part accessible in Apple and Android two distinct dialects are utilized to manufacture these.

There are some JavaScript interview questions that are asked given below:

How to create a class?

JavaScript does not have a class definition. To mimic classes in JavaScript functions can
be used to declare a class.
Example :
Let’s create a student class in JavaScript which takes two parameters name and roll as
property. The code will look like below –
function Student(name,roll){ = name;
this.roll = roll;

How to create an object?

An object in JavaScript can be created using two ways:
New Keyword:
To create a student object from the above student class we can call the Student function using new keyword.
var student1 = new Student(‘sandeep’,2)
Anonymous Object:
Anonymous objects can be created using pair of curly braces containing property name and value pairs.
Var rose = {‘color’: ’red’}

How to declare a private and a public member?

Private members are declared using var keyword and constructor function.
function Student(name,roll){ var id= ABCD123; = name;
this.roll = roll;

When a Student object will be created the propertied name and roll will be accessible using dot operator but id will not be accessible as it behaves as a private member and
return undefined on call.
javascript interview questions
The above chrome console is showing a student1 object is property is accessible as it is showing sandeep on call. So name is a public property for the student object. But id property is not accessible and returned undefined on call. This shows id is a private property in student1 object.

What is prototype property?

By Using Prototype we can add new members to an existing object. Every JavaScript object has this property internally. Initially it is an empty object.

How to call other class methods?

Using call() and apply() method we can use methods from different context to the current context. It is really helpful in reusability of code and context binding.

  • call() : It is used to calls a function with a given this value and arguments provided individually.
  • apply(): It is used to call a function with a given this value and arguments provided as an array.

Below code has two function getTypeOfNumber() and getTypeOfAllNumber(). The details pf these functions are below.
getTypeOfNumber : This method takes single number as parameter and return the type either Even or Odd.
getTypeOfAllNumber : This method takes array of numbers as parameter and return the types in an array with Even or Odd.
var MyNumber = {
getTypeOfNumber : function(number){
var type = (number % 2 === 0) ? “Even” : “Odd”; return type;
getTypeOfAllNumber : function (){
var result = [],i=0;
for (; i < arguments.length; i++){
var type =,arguments[i]) ;
return result;
var typeOfNumber =,21) console.log(typeOfNumber)
var typeOfAllNumber =
MyNumber.getTypeOfAllNumber.apply(null,[2,4,5,7 8,21])

What is differential inheritance?

Differential Inheritance is a common prototype-oriented model that uses the concept that most objects are derived from other, more generic objects, and only differ in a few small aspects. Each object maintains a reference to its prototype and a table of properties that are different.

How can you distinguish scope and context in JavaScript?

Scope pertains to the visibility of variables and context refers to the object to which a method belongs and can be changed by using call or applies.

How Event works in javascript?

Event propagation follows two phases capturing and bubbling phase.
Quick JavaScript Interview Questions.jpg

  • Capturing Phase:In this phase, event first makes its way downwards from the DOCUMENT to the target element by passing all inner elements.
  • Bubbling Phase:In this phase event makes its way back upwards from the target element to DOCUMENT by passing all outer wrapped elements.

What are the two programming paradigms important for JavaScript app developers?

JavaScript is a multi-paradigm language, supporting imperative/procedural programming along with OOP (Object Oriented Programming) and functional programming. JavaScript supports OOP with prototypal inheritance.

What is functional programming?

Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data. Lisp (specified in 1958) was among the first languages to support functional programming, and was heavily inspired by lambda calculus. Functional programming is an essential concept in JavaScript (one of the two pillars of JavaScript). Several common functional utilities were added to JavaScript in ES5.
Focus is on: – Function purity – Avoiding side-effects – Simple function composition.

What is the difference between classical inheritance and prototypal inheritance?

Class Inheritance: instances inherit from classes (like a blueprint – a description of the class), and create sub-class relationships: hierarchical class taxonomies. Instances are typically instantiated via constructor functions with the new keyword. Class inheritance may or may not use the class keyword from ES6.
Prototypal Inheritance: instances inherit directly from other objects. Instances are typically instantiated via factory functions or Object.create(). Instances may be composed from many different objects, allowing for easy selective inheritance.

When is prototypal inheritance an appropriate choice?

There is more than one type of prototypal inheritance:

  • Delegation (i.e., the prototype chain).
  • Concatenative (i.e. mixins, Object.assign()).
  • Functional (Not to be confused with functional programming. A function used to create a closure for private state/encapsulation).

Each type of prototypal inheritance has its own set of use-cases, but all of them are equally useful in their ability to enable composition, which creates has-a or uses-a or can-do relationships as opposed to the is-a relationship created with class inheritance.

What are JavaScript data types?

Primary Data Types

  • String
  • Number
  • Boolean

Composite Data Types

  • Object
  • Array

Special Data Types

  • Null
  • Undefined

What is the difference between “==” and “===”?

“==” checks only for equality in value whereas “===” is a stricter equality test and returns false if either the value or the type of the two variables are different. So, the second option needs both the value and the type to be the same for the operands.

What is an undefined value in JavaScript?

Undefined value means the:

  • Variable used in the code doesn’t exist
  • Variable is not assigned to any value
  • Property doesn’t exist

What are the different types of errors in JavaScript?

There are three types of errors:
Load time errors: Errors which come up when loading a web page like improper syntax errors are known as Load time errors and it generates the errors dynamically.
Run time errors: Errors that come due to misuse of the command inside the HTML language.
Logical Errors: These are errors that occur due to the wrong logic performed on a function.

What is event bubbling in javascript?

JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of parent will also work as if it were clicked too.

What is a “closure” in JavaScript?

A closure is a function defined inside another function (called the parent function), and has access to variables that are declared and defined in the parent function scope.
The closure has access to variables in three scopes:

  • Variables declared in their own scope
  • Variables declared in a parent function scope
  • Variables declared in the global namespace

How to empty an array in JavaScript?

For Instance,
vararrayList= [’a’,’b’,’c’,’d’,’e’,’f’];

What is ‘this’ keyword in JavaScript?

thiskeyword is used to point at the current object in the code. For instance: If the code is presently at an object created by the help of the ‘new’ keyword, then ‘this’ keyword will point to the object being created.

What is the difference between ViewState and SessionState?

ViewState is specific to a page in a session. SessionState is specific to user specific data that can be accessed across all pages in the web application.

Does JavaScript support automatic type conversion?

Yes JavaScript does support automatic type conversion, it is the common way of type conversion used by JavaScript developers.

How can you read and write a file using JavaScript?

There are two ways to read and write a file using JavaScript:

  • Using JavaScript extensions
  • Using a web page and Active X objects

How can you read and write a file using JavaScript?

The parseInt() function is used to convert numbers between different bases. parseInt() takes the string to be converted as its first parameter, and the second parameter is the base of the given string.

What is the use of Void(0)?

Void(0) is used to prevent the page from refreshing and parameter “zero” is passed while calling. Void(0) is used to call another method without refreshing the page.

What are JavaScript Cookies?

A function that is declared without any named identifier is known as an anonymous function. In general, an anonymous function is inaccessible after its declaration.

What is unobtrusive Javascript?

Unobtrusive JavaScript is basically a JavaScript methodology that seeks to overcome browser inconsistencies by separating page functionality from structure. The basic premise of unobtrusive JavaScript is that page functionality should be maintained even when JavaScript is unavailable on a user’s browser.

What is the difference between window.onload and onDocumentReady?

The window.onload event won’t trigger until every single element on the page has been fully loaded, including images and CSS. The downside to this is it might take a while before any code is actually executed. You can use onDocumentReady to execute code as soon as the DOM is loaded instead.

What is a DOM?

Document Object Model (DOM) is a programming API for HTML and XML document. JavaScript is most widely used language to access these DOM API properties and methods.

What are the Different Properties involved in DOM?

name : It has the name of the Attribute.
namespaceURI: It represents namespace URI of the node.
nextSibling: It contains the next sibling of the Node in document source order.
nodeName : This represents name of the node. nodeType: It represents type of the node.
nodeValue: It has value of the node.
ownerDocument: It has reference to the Document object that contains the Node.
ownerElement : It has reference of the Element to which the Attribute belongs.
parentNode: It represents parent Node to which the node belongs.
prefix: It represents namespace prefix of the node.
previousSibling : It has the previous sibling of the Node in document source order.
text: It has contents of all the text nodes contained by the Node and any element nodes that it contains.
value : It has value of the Attribute.
attributes: Represents collection of Attribute objects.
childNodes : Represents NodeList collection of node objects.
data: Represents text stored within a TextNode, CDATASection, or Comment.
documentElement: It contains root element node of the document.
firstChild: This is first child of the Node in document source order.
lastChild: This is the last child of the Node object in document source order.
length: It represents number of elements in the collection.
localName: It has local name of the node..


With every one of the highlights in a frontend and backend advancement JavaScript helps in supporting both and making some of the best applications that can be utilized around the world. So this is the language that is to remain.

Have Some Questions? Share with us

Leave a Comment

Your email address will not be published.

Scroll to Top