• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

JavaScript Interview Questions & Answers

What is JavaScript?

JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight and cross platform. It is widely used for client side validation.

What is the difference between JavaScript and jscript?

Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue.In other words, you can say JScript is same as JavaScript, but it is provided by Microsoft.

How to write a hello world example of JavaScript?

A simple example of JavaScript hello world is given below. You need to place it inside the body tag of html.

<script type=”text/javascript”>  

document.write(“JavaScript Hello World!”);  

</script>  

How to use external JavaScript file?

I am assuming that js file name is message.js, place the following script tag inside the head tag.

<script type=”text/javascript” src=”message.js”></script>  

Is JavaScript case sensitive language?

Yes.

What is BOM?

BOM stands for Browser Object Model. It provides interaction with the browser. The default object of browser is window.

What is DOM? What is the use of document object?

DOM stands for Document Object Model. A document object represent the html document. It can be used to access and change the content of html.

What is the use of window object?

The window object is automatically created by the browser that represents a window of a browser.

It is used to display the popup dialog box such as alert dialog box, confirm dialog box, input dialog box etc.

What is the use of history object?

The history object of browser can be used to switch to history pages such as back and forward from current page or another page. There are three methods of history object.

history.back()

history.forward()

history.go(number): number may be positive for forward, negative for backward.

How to write comment in JavaScript?

There are two types of comments in JavaScript.

Single Line Comment: It is represented by // (double forward slash)

Multi Line Comment: It is represented by slash with asterisk symbol as /* write comment here */

How to create function in JavaScript?

To create function in JavaScript, follow the following syntax.

function function_name(){  

//function body  

}  

What are the JavaScript data types?

There are two types of data types in JavaScript:

Primitive Data Types

Non-primitive Data Types

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

The == operator checks equality only whereas === checks equality and data type i.e. value must be of same type.

How to write html code dynamically using JavaScript?

The innerHTML property is used to write the HTML code using JavaScript dynamically. Let’s see a simple example:

document.getElementById(‘mylocation’).innerHTML=”<h2>This is heading using JavaScript</h2>”;   

How to write normal text code using JavaScript dynamically?

The innerText property is used to write the simple text using JavaScript dynamically. Let’s see a simple example:

document.getElementById(‘mylocation’).innerText=”This is text using JavaScript”;   

How to create objects in JavaScript?

There are 3 ways to create object in JavaScript.

By object literal

By creating instance of Object

By Object Constructor

Let’s see a simple code to create object using object literal.

emp={id:102,name:”Rahul Kumar”,salary:50000}   

How to create array in JavaScript?

There are 3 ways to create array in JavaScript.

By array literal

By creating instance of Array

By using an Array constructor

Let’s see a simple code to create array using object literal.

var emp=[“Shyam”,”Vimal”,”Ratan”];    

What does the isNaN() function?

The isNan() function returns true if the variable value is not a number.

What is the output of 10+20+”30″ in JavaScript?

3030 because 10+20 will be 30. If there is numeric value before and after +, it is treated is binary + (arithmetic operator).

What is the output of “10”+20+30 in JavaScript?

102030 because after a string all the + will be treated as string concatenation operator (not binary +).

Difference between Client side JavaScript and Server side JavaScript?

Client side JavaScript comprises the basic language and predefined objects which are relevant to running java script in a browser. The client side JavaScript is embedded directly by in the HTML pages. This script is interpreted by the browser at run time.

Server side JavaScript also resembles like client side java script. It has relevant java script which is to run in a server. The server side JavaScript are deployed only after compilation.

In which location cookies are stored on the hard disk?

The storage of cookies on the hard disk depends on OS and the browser.

The Netscape navigator on Windows uses cookies.txt file that contains all the cookies. The path is : c:\Program Files\Netscape\Users\username\cookies.txt

The Internet Explorer stores the cookies on a file username@website.txt. The path is: c:\Windows\Cookies\username@Website.txt.

What is the real name of JavaScript?

The original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape. In September of 1995, the name was changed to LiveScript. In December 1995, after receiving a trademark license from Sun, the name JavaScript was adopted.

What is the difference between undefined value and null value?

Undefined value: A value that is not defined and has no keyword is known as undefined value. For example:

int number;//Here, number has undefined value.  

Null value: A value that is explicitly specified by the keyword “null” is known as null value. For example:

String str=null;//Here, str has a null value.  

How to set the cursor to wait in JavaScript?

The cursor can be set to wait in JavaScript by using the property “cursor”. The following example illustrates the usage:

<script>  

window.document.body.style.cursor = “wait”;   

</script>  

What is this?

var myArray = [[[]]];  

Three dimensional array.

Are Java and JavaScript same?

No, Java and JavaScript are the two different languages. Java is a robust, secured and object-oriented programming language whereas JavaScript is a client side scripting language with some limitations.

What is negative infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

What is difference between View state and Session state?

“View state” is specific to a page in a session whereas “Session state” is specific to a user or browser that can be accessed across all pages in the web application.

What are the pop up boxes available in JavaScript?

Alert Box

Confirm Box

Prompt Box

How can we detect OS of the client machine using JavaScript?

The navigator.appVersion string can be used to detect the operating system on the client machine.

How to submit a form using JavaScript by clicking a link?

Let’s see the JavaScript code to submit form on clicking the link.

<form name=”myform” action=”index.php”>  

Search: <input type=’text’ name=’query’ />  

<a href=”javascript: submitform()”>Search</a>  

</form>  

<script type=”text/javascript”>  

function submitform()  

{  

  document.myform.submit();  

}  

</script>  

Is JavaScript faster than ASP script?

Yes, because it doesn’t require web server’s support for execution.

How to change the background color of HTML document using JavaScript?

<script type=”text/javascript”>  

document.body.bgColor=”pink”;  

</script>  

How to handle exceptions in JavaScript?

By the help of try/catch block, we can handle exceptions in JavaScript. JavaScript supports try, catch, finally and throw keywords for exception handling.

Our design of course tutorials and interview questions is practical and informative. At TekSlate, we offer resources to help you learn various IT courses. We avail both written material and demo video tutorials. For in-depth knowledge and practical experience explore Online JavaScript Training.


Summary
Review Date
Reviewed Item
JavaScript Interview Questions & Answers
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on JavaScript Interview Questions & Answers"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.