JAVASCRIPT Interview Questions and Answers

JavaScript often abbreviated as JS, is a lightweight, high level, interpreted or JIT compiled programming language with first-class functions. It is a client-side scripting language.Most well known as scripting language for Web pages. It is based on ECMAScript.

11) What are the primitive data types in JavaScript?

A primitive is a basic data type that’s not built out of other data types. It can only represent one single value. All primitives are built-in data types by necessity, (the compiler has to know about them,) but not all built-in data types are primitives. In JavaScript there are 5 primitive data types are available they are undefined, null, boolean, string and number are available.Everything else in Javascript is an object.

12) What does the instanceof operator do?

In Javascript instanceof operator checks whether the object is an instance of a class or not: Example : Square.prototype = new Square(); console.log(sq instanceof Square); // true

13) What is Javascript BOM?

BOM stands for “Browser Object Modal” that allows Javascript to ‘talk’ to the browser, no standards, modern browsers implement similar BOMS – window, screen, location, history, navigator, timing, cookies.

14) Explain Event bubbling in JavaScript?

Event Bubbling : Bubbling just works like the bubbles, the event gets handled by the innermost element and then propagated to the outer element.

In this example, suppose the click event did occur in the ‘li’ element in bubbling model the event will be handled first by ‘li’ then by ‘ul’ and at last by ‘div’ element.

15) Explain Event Capturing in JavaScript?

Event Capture: The capture procedure is rarely used but when it’s used it proves to be very helpful. This process is also called ‘trickling’. In this process, the event is captured first by the outermost element and then propagated to the innermost element. For example:

In this example, suppose the click event did occur in the ‘li’ element, in that case capturing event it will be first handled ‘div’, then ‘ul’ and at last the target element will be hit that is ‘li’.

16) List HTML DOM mouse events?

HTML DOM mouse events are :  onclick, ondblclick, mousemove, mousedown, mouseover, mouseout, and mouseup.

17) In Javascript are calculations with fractional numbers guaranteed to be precise?

NO, calculations with fractional numbers are not guaranteed to be precise in Javascript.

18) What close() does in Javascript?

In Javascript close() method is used to close the current window. You must write window.close() to ensure that this command is associated with a window object and not some other JavaScript object.

19) What are different types of Popup boxes available in Javascript?

In Javascript there are 3 types of Popup Boxes are available:

Alert,Confirm and Prompt.

20) How can you create an array in Javascript?

There are 3 different ways to create an array in Javascript. They are :

1) By array literal : var myArray=[value1,value2...valueN];

2) By creating instance of Array: var myArray=new Array();

3) By using an Array constructor : var myArray=new Array('value1','value2',...,'valueN');