65 javascript interview questions and answers


Javascript interview questions and answers

<<Previous  Next>>
1.JavaScript vs. Jscript

Latest answer: Both JavaScript and Jscript are almost similar. Java script was developed by Netscape. Microsoft implemented its own scripting language and named it as Jscript...........
Read answer

2.What is the difference between Client side JavaScript and Server side JavaScript.

Latest answer: Client side java script comprises the basic language and predefined objects which are relevant to running java script in a browser. The client side java script is embedded directly by in the HTML pages.............
Read answer

3.Where are cookies actually stored on the hard disk?

Latest answer: The storage of cookies on the hard disk depends on OS and the browser. The Netscape navigator on Windows, the file cookies.txt contains all the cookies. The path is :.........
Read answer

4.What is the difference between a web-garden and a web-farm?

Latest answer: Web garden is a web hosting system. It is a setup of multi processors in single server.

Read answer

5.What is the difference between SessionState and ViewState?

Latest answer: The values of controls of a particular page of the client browser is persisted by ViewState at the time of post back operation is done. If the user requests another page, the data of previous page is no longer available............
Read answer

6.How to Accessing Elements using javascript?

Latest answer: The elements of JavaScript are accessed by their names. By default the browser is accessed by the element ‘windows’ and the page by ‘document’. The corresponding element has user defined names for forms and its elements............
Read answer

7.What is the difference between undefined value and null value?

Latest answer: Undefined value: A value that is not defined and has no keyword is known as undefined value. For example in the declaration, int number; the number has undefined value..........
Read answer

8.How to set the cursor to wait in JavaScript?

Latest answer: The cursor can set to wait in JavaScript by using the property ‘cursor’ property. The following example illustrates the usage.............
Read answer

9.What is decodeURI(), encodeURI() in JavaScript?

Latest answer: To send the characters that can not be specified in a URL should be converted into their equivalent hex encoding. To perform this task the methods encodeURI() and decodeURI() are used...........
Read answer

10.Methods GET vs. POST in HTML forms.

Latest answer: Encoding form data into URL is needed by the GET method. The form data is to be appeared within the message body , by the POST method. By specification, GET is used basically for retrieving data where as POST is used for data storing, data updating, ordering a product or even e-mailing.............
Read answer

11.What does the EnableViewStateMac setting in an aspx page do?

Latest answer: EnableViewStateMac setting is a security measure in ASP.Net. It ensures the view state for a page not to tamper. To to so “ EnableViewStateMac=true “is used............
Read answer

12.What are windows object and navigator object in JavaScript?

Latest answer: Windows object is top level object in Java script. It contains several other objects such as, document, history, location, name, menu bar etc., in itself. Window object is the global object for Java script that is written at client-side.........
Read answer

13.How to detect the operating system on the client machine in JavaScript?

Latest answer: The navigator.appVersion string should be used to find the name of the operating system on the client machine..............
Read answer

14.How to set a HTML document's background color in JavaScript?

Latest answer: Using document object the back ground color can be changed by JavaScript.........
Read answer

15.How do you assign object properties in JavaScript?

Latest answer: Java script object properties are assigned like assigning a value to a variable. For example, the title property of document object can be assigned as follows:

document.title="Welcome to the world of Javascripting";............
Read answer

16.What is JavaScript?  

Latest answer: JavaScript is a scripting language most often used for client-side web development...................
Read answer

17.What boolean operators does JavaScript support?

Latest answer: ==, !=, < , >, <=, >=.............
Read answer

18.Is a javascript script faster than an ASP script?  

Latest answer: JSP is faster then ASP as the script is run on the client side...................
Read answer

19.What is == operator ?     

Latest answer: The ‘==’ operator is a boolean comparison operator that returns true if the variables................
Read answer

20.What is negative infinity?

Latest answer: It’s a number that is obtained by dividing a negative number by zero. (in JSP)...................
Read answer

21.What’s relationship between JavaScript and ECMAScript?

Read answer

22.What does isNaN function do?

Latest answer: The isNaN function determines if the value is a number or not and depending upon the result, it returns true or false.................
Read answer

23.How to read and write a file using javascript?

Latest answer: There are two ways to do it: 1. Using JavaScript extensions (runs from JavaScript Editor), or 2. Using a web page and ActiveX objects (Internet Explorer only)......................
Read answer

24.How do you create a new object in JavaScript?

Latest answer: In order to generate dynamic content, JSP provides for creating, modifying and interacting with Java objects. The implicit objects like page, config, request, etc are called so because their availability in the in JSP page is automatic.....................
Read answer

25.How to create arrays in JavaScript? 

Latest answer: Although you can create the arrays using ‘new’ (var myArray = new myArray[10];), it is recommended that you create it in the following way: var myArray = [];....................
Read answer

Test your Javascript knowledge with our multiple choice questions!

Test your Java skills

Java part 1 (39 questions)
Java part 2 (40 questions)
EJB (20 questions)
JDBC (20 questions)
Applet (20 questions)
Struts (21 questions)
Servlets (20 questions)
Java web services (20 questions)

<<Previous  Next>>

Also read
OFBiz Service Engine

Defining and creating a Java service
Service parameters
Special unchecked (unmatched) IN/OUT parameters
Security-related programming
Calling services from code (using dispatcher)
IN/OUT parameter mismatch when calling services
Sending feedback; standard return codes success, error and fail
Implementing Service Interfaces
Synchronous and asynchronous services
Using the Service Engine tools
ECAs: Event Condition Actions

The components in the ASP.NET 2.0 AJAX packaging


Potential benefits of using Ajax


Potential problems with AJAX


Who Benefits from AJAX?

AJAX is employed to improve the user’s experience. A request is made for the initial page rendering. After that, asynchronous requests to the server are made. An asynchronous request is a background request to send or receive data in an entirely nonvisual manner.............

Write your comment - Share Knowledge and Experience

Discussion Board
Javascript interview questions and answers

Are there any predefined constant provided by the browser with the key code values that can be reused?
Use of global object, named as KeyEvent object, used in firefox browser, providing set of pre-defined constants that reflect the keys, which are used on keyboards. The constant’s name used is: DOM_VK_KEYNAME, with values representing the keydown/keyup key codes for the respective keys. For example, DOM_VK_SHIFT is 16, DOM_VK_ESCAPE is 27.

How can I set up my own JavaScript error handler?
To set up your own JavaScript error handler some optional parameters has to be known. These parameters are as follows:
- Textual description of error
- Address (URL) of page on which error occurred
- Number of line in which error occurred
If you want to invoke the default error handler of the browser, then your function should return (false) or vice versa. Example code:
function handlerFunction(description,page,line)
{ // put error-handling operators here
return true;}

How do I use JavaScript to password-protect my Web site?
There are several ways in which you can use JavaScript to password-protect your website. This can be done by setting the password by using the given name or pathname of HTML file on your site. Set the location to value entered in the field. Entry of wrong password will result in “invalid URL” error. If password protect pages requires more security then you can set temporary cookies on the page.

How can I prevent others from reading/stealing my scripts or images?
There are no assertive measures which can be taken to foolproof your scripts and images, but preventive measures can be taken like copyrighting your pages, putting watermark on your images and applying non-technological way to protect your images. Scripts are difficult to protect as they can be accessed through many applications and many programs by using the web browsers.

Rohit Sharma 12-11-2011 11:19 AM

JavaScript interview questions and answers

How do I write script-generated content to another window?
You can use the methods winRef.document.writeln() or winRef.document.write() to write the script-generated content to another window. winRef stands for windows reference, it is being returned by window.open() method. Use of winRef.document.close() can be used if you want your script’s output to show up. Example code:
writeConsole('Hello world!');
function writeConsole(content) {
top.consoleRef=window.open('','myconsole', 'width=350,height=250'
top.consoleRef.document.writeln( '<html><head><title>Console</title></head>' +' top.consoleRef.document.close() }

How can I request data from the server without reloading the page in the browser?
JavaScript code which is being present and loaded in client browser, can request for data from the web server using XMLHttpRequest object. XMLHttpRequest.open() method is used to open the connection, not to send the request to web server. But, use of the function XMLHttpRequest.send() sends the request in real time. Example code is given below as:
var oRequest = new XMLHttpRequest();
var sURL = "http://"+ self.location.hostname + "/hello/requested_file.htm";
if (oRequest.status==200) alert(oRequest.responseText);
else alert("Error executing XMLHttpRequest call!");

How do I add a JavaScript event handler to an HTML page element?
You can use inline event handlers to add a JavaScript handler to an HTML page element. The disadvantage of this technique is that it allows you to have one handler per element. There are different browsers which allow you to have dynamic handler added to the HTML page element. Example of inline event handler is given below:
<a href="ineh.htm" onlick="alert('Hello!')">Good Morning!</a>
// event handlers added by assignment (usually right after the page loads), e.g.:

Rohit Sharma 12-11-2011 11:18 AM

JavaScript interview questions and answers

How do I retrieve a cookie with a given name using a regular expression?
You can use readCookie() function to read the cookie. It provides sufficient arguments that one can find it, flexible to use. It takes cookieName as a parameter and other statements in the block. Below function uses the cookie function as well as regular expression to show the functionality:
function readCookie(cookieName)
{ var rx = new RegExp('[; ]'+cookieName+'=([^\\s;]*)');
var sMatch = (' '+document.cookie).match(rx);
if (cookieName && sMatch) return unescape(sMatch[1]);
return '';

What value does prompt() return if the user clicked the Cancel button?
Return value of prompt() function depends on browsers. Most of the browsers return the value as null and some return as empty string (“ “). IE is one of the browser which gives the error of empty string when clicked the cancel button by the user, otherwise all the recent browser return the value as null. The code to check this is as follows:
userInput = prompt('Prompt text','Suggested input');
if (userInput) {
// do something with the input

Why does the browser display the slow script warning?
When JavaScript on your browser is running but, it is not responding from a long time, then browser may display a warning message and give the user an option to terminate the script. Example, while loading a video application on Internet Explorer 8.0, it displays Yes/No dialog message like this:
Stop running this script?
If it continues to run, your computer might become unresponsive.

Rohit Sharma 12-11-2011 11:16 AM


Interview questions
Home | About us | Sitemap | Contact us