JavaScript Interview Questions and Answers (294) - Page 4

What is Chakra ?

It is a new javaScript engine developed by Microsoft for its IE9 web browser.

A distinctive feature of the engine is that it include a new JavaScript compiler that compiles the scripts on a separate CPU core and convert into high-quality native machine code.

The engine is also able to access the computer's graphics processing unit (GPU), in particular for 3D graphics and video.

It also include a new interpreter for executing script on traditional web pages, and improvements to the JavaScript runtime and libraries.
what is node.js ?

Node.js is an open-source server-side JavaScript platform for building high performance scalable network program.

It is built on Chrome's V8 JavaScript runtime and the framework is also using other two open source projects like libev and libeio.

It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
What is the difference between == and === ?

JavaScript has both strict and type-converting equality comparison. For strict equality the objects being compared must have the same type and also the below characteristics:

• Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
• Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another.
• Two Boolean operands are strictly equal if both are true or both are false.
• Two objects are strictly equal if they refer to the same Object.
• Null and Undefined types are == (but not ===).


== is equal to
=== is exactly equal to (value and type)
0==false // true
0===false // false, because they are of a different type
1=="1" // true, auto type coercion
1==="1" // false, because they are of a different type
What is a javascript object ?

An object is a special kind of data, with a collection of properties and methods.
Let us discuss an example to have a clear idea:
A person is an object. Properties are the values associated with the object. The persons' properties include name, height, weight, age, skin tone, eye color, etc. All persons have these properties, but the values of those properties will differ from person to person.
Objects also have methods. Methods are the actions that can be performed on objects. The persons' methods could be eat(), sleep(), work(), play(), etc.

The syntax for accessing a property of an object is:





You can call a method with the following syntax:



How do you submit a form using Javascript ?

By using below snippet, we can submit a form using Javascript.

Use document.forms[0].submit();

Here, in the above snippet, 0 refers to the index of the form – if you have more than one form in a page, then the first one has the index 0, second has index 1 and so on.
How to detect the operating system on the client machine ?

In order to detect the operating system on the client machine, your script can analyze the value of navigator.appVersion or navigator.userAgent.


// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

On your system, this script yields the following result:

Your OS: Windows

What is the importance of the HTML DOCTYPE ?

The doctype declaration should be the first thing in an HTML document, before the html tag.

The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.

The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers can render the content correctly.
How do you convert numbers between different bases in JavaScript ?

By using the parseInt() function, we can convert numbers between different bases in JavaScript. This function takes a string as the first parameter, and the base as a second parameter.


To convert hexadecimal 3F to decimal, we use
parseInt ("3F", 16);
What is the difference between GET and POST in HTML forms ?

The differences between both are described as follows:

GET: Parameters are passed in the querystring. This method appends the form-data to the URL in name/value pairs. Maximum amount of data that can be sent via the GET method is limited to about 2kb. Never use the "get" method to pass sensitive information! (password or other sensitive information will be visible in the browser's address bar).

POST: Parameters are passed in the request body. This method sends the form-data as an HTTP post transaction. There is no limit to the amount of data that can be transferred using POST. However, there are limits on the maximum amount of data that can be transferred in one name/value pair.

For example, go through the below link.
What does the "Access is Denied" IE error mean ?

The "Access Denied" error in any browser is due to the following reason:
If a javascript in one window or frame tries to access another window or frame whose document's domain is different from the document containing the script, then this error occurs.
What is Modernizr ?

It is an open-source JavaScript library that helps you build the next generation of HTML5 and CSS3-powered websites.

It provides a more modern way to test features that a browser supports and can even handle loading additional scripts called shims or polyfills that fill in holes that older browsers may have.

Two different types of scripts are available, one for a development script and custom production script.
How to get the contents of an input box using Javascript ?

By using the "value" property, you can get the contents of an input box.


var myValue = window.document.getElementById("MyTextBox").value;

How to determine the state of a checkbox using Javascript ?

To determine the state of a checkbox using Javascript, you can use the following example.


var checkedP = window.document.getElementById("myCheckBox").checked;

What is the difference between undefined value and null value ?

Following are the basic diferences between undefined value and null value.
(i)Undefined value cannot be explicitly stated i.e., there is no keyword called undefined whereas null value has keyword called null.
(ii)Typeof undefined variable or property returns undefined whereas type of null value returns object.
What is the use of eval() in javascript ?

The eval() method is allows you to execute code snippets during execution.


<script type="text/javascript">
var USA_Texas_Austin = "521,289";
document.write("Population is "+eval("USA_"+"Texas_"+"Austin"));
This produces
Population is 521,289

How to create a function using function constructor ?

The following example gives detailed explanation on this:
It creates a function called square with argument x and returns x multiplied by itself.

var square = new Function ("x","return x*x");

What is Backbone.js ?

It gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

It is data binding framework.
What is BSON ?

Bin­ary JSON (BSON), is a bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments.

Like JSON, BSON sup­ports the em­bed­ding of doc­u­ments and ar­rays .

BSON also con­tains ex­ten­sions that al­low rep­res­ent­a­tion of data types that are not part of the JSON specification.

Its main features are Lightweight,Traversable and Efficient.
What is output in javascript? 1+2+"3"+4+5

NOTE: This is objective type question, Please click question title for correct answer.
What is TypeScript ?

TypeScript is a programming language from Microsoft that makes it easier to write cross-platform, application scale, JavaScript that runs in any browser or in any host.

TypeScript also supports interfaces, classes (the same syntax as currently proposed by the next version of EcmaScript), modules, file importing, public and private data, and probably more.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories