Thursday, February 15, 2018


Top 35 Essential JavaScript Interview Questions and Answers

Here I am sharing top 35 essential javascript interview questions and answers for freshers and experienced. This list of javascript interview questions and answers will be helpful for javaScript beginner who just started their career as javascript developer, and surely help you during interview session.

Question #1 - What is JavaScript?

JavaScript is a client side scripting language with an inbuilt object-oriented capability that allows developers to build up client side validations with HTML pages. It is object-based, lightweight and cross platform.

Question #2 - How to use external JavaScript file in a HTML page?

Lets assume a js file name is myscript.js. So to use this external file we write code as below 

<script type="text/javascript" src="myscript.js"></script>  

Question #3 - what are the JavaScript properties.

Below are the properties of JavaScript −
  • JavaScript is open and cross-platform.
  • JavaScript is a lightweight, interpreted programming language.
  • JavaScript is client side scripting language.
  • JavaScript is easy to integrate with HTML.
  • JavaScript is complementary to and integrated with Java.
  • JavaScript is designed for creating network-centric applications.
Question #4 - What is arguments object in JavaScript?

JavaScript variable arguments represents the arguments passed to a function.
Question #5 - What is the use of HTML5 Canvas element ?

Canvas used to draw graphics on a web page by the help of javascript.
Question #6 -  What is DOM? What is the use of document object?

DOM known as Document Object Model. A document object represent the html document. mostly It is used to access and change the content of html.
Question #7 - Is javascript case sensitive?

Yes, Javascript is case sensitive.

Question #8 - What is difference between == and === operator?

== is a comparison operator while === is a hard equality operator. == checks value only while === check value and datatype. 5=="5" id true but 5==="5" is false.

Question #9 - What is an AJAX request and what is a simple example of where a AJAX request would be used.

AJAX known as "Asynchronous JavaScript and XML". It is commonly used client side process to get or post data from remote server without reloading page.

Question #10 - What is Event bubbling and Event Capturing.

Event Propagation are the order that event fire on element. 

Bubbling :-

Bubbling is when a event fire on the element and then bubble up DOM Tree. Means First child and then parent will call. 

Capturing :-

Capturing is exactly opposite. First parent node is called and then propagates down towards target element.

Question #11 - How to get value of input box using jQuery ?

You can get value of input box using below function..


Question #12 - how to remove a class in jquery?

You can remove a class form a html element like :-
<p class="perag">This is a paragraph.</p>

Question #13 - What are JavaScript Data Types?

Below are the JavaScript Data types:-

  • String
  • Boolean
  • Number
  • Function
  • Object
  • Undefined
Question #14 - What are the features of jQuery, has been used in web applications?

jQuery uses features like Sliding, File uploading and accordian in web applications.
Question #15 - What are the basic selectors in jQuery?

Following are the basic selectors in jQuery:
  • Element ID
  • CSS Name
  • Tag Name
  • DOM hierarchy
Question #16 - Assign Any Variable Name A Value Of “hello World”, And Print That Variable’s Contents To The Console.?

  var t = “Hello World”;  

Question #17 - How do you select all elements with the class of “selected” in jQuery?

We use below code to select all elements with the class.


Question #18 - How to convert a string to lowercase?

You can convert a string to lowercase by following below script..
var str='I Love';
str = str.toLowerCase();

Output:- i love
Question #19 - How to modify the URL of page without reloading the page?

We use pushState javascript function as below..
window.history.pushState('page2', 'I Love PhpMyPassion', '/nextpage.php');

Question #20 - How to get current date in JavaScript?

We use below code to get current date in JavaScript.
var today = new Date();

Question #21 - How to open URL in new tab in javascript?

We use below code to open URL in new tab in javascript.'','_blank');

Question #22 - How to declare a variable as CONSTANT  in JavaScript like in PHP?

You can declare a variable  as constant in javascript as below.
var CONSTANT_NAME = "constant value";

Question #23 - How to set a default parameter value for a JavaScript function?

/** Here stClass is parameter in which we have set the default value i.e senior_secondary **/
function functionGetClass(name, stClass)
   stClass = typeof stClass !== 'undefined' ? stClass : 'senior_secondary';
    console.log('name='+name+', Class= '+stClass);


Question #24 - How to convert JSON Object to String?

var pobject=['Php','Is','My','Passion']

Question #25 - How to convert JSON Object to String?

var jsonpData = '{"name":"phpmypassion","year":2017}';
var pobject = JSON.parse(jsonpData);

Question #26 - What is the best way to detect a mobile device in jQuery?

We can detect a mobile device in jQuery using below code -
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {


Question #27 - How to detect mobiles including ipad using navigator.useragent in javascript?

We can detect a mobile device including ipad using navigator.useragent in jQuery using below code -
 if(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) ||  navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/iPhone/i)){
        console.log('Calling from Mobile');      
    console.log('Calling from Web');      

Question #28 - How do I declare a namespace in JavaScript?

We use below code to declare a namespace in JavaScript.
var myNamespace = {

    functionA: function() {   },

    functionB: function() {    }

    functionC: function() {    }


Question #29 - How can you create an Array in JavaScript?

You can create an array in JavaScript using the below code.
var x = [];
var y = [1, 2, 3, 4, 5];

Question #30 - How can you create an Object in JavaScript?

JavaScript supports Object concept and you can create an object using the object literal as follows −
var student= {
   name: "sonia",
   age: 20

Question #31 - How can you read properties of an Object in JavaScript?

We can write and read properties of an object using the dot notation as follows −
// Getting object properties  // ==> sonia
student.age   // ==> 20
// Setting object properties = "monica"  // <== monica
student.age  = "22"      //  <== 22

Question #32 - What is a named function in JavaScript? How to define a named function?

A named function always declare with a name when it is defined. A named function can be defined using function keyword as below−
function name(){
   // do some stuff here

Question #33 - What is the purpose of 'this' operator in JavaScript?

"this" keyword always refers to the current context in JavaScript.

Question #34 - How many types of functions JavaScript supports?

A function in JavaScript can be either named or anonymous.

Question #35 - What are the JavaScript data types?

There are two types of data types in JavaScript:

  • Primitive Data Types
  • Non-primitive Data Types

About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a hug of information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :