Expert JavaScript Developer

  Home  Client Side Scripting  Expert JavaScript Developer


“Expert JavaScript Developer Frequently Asked Questions in various Expert JavaScript Developer job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”



208 Expert JavaScript Developer Questions And Answers

101⟩ What are the decodeURI() and encodeURI()?

EncodeURl() is used to convert URL into their hex coding. And DecodeURI() is used to convert the encoded URL back to normal.

<script>

var uri="my test.asp?name=ståle&car=saab";

document.write(encodeURI(uri)+ "

");

document.write(decodeURI(uri));

</script>

Output -

my%20test.asp?name=st%C3%A5le&car=saab

my test.asp?name=ståle&car=saab

 132 views

102⟩ What are global variables? How are these variable declared and what are the problems associated with using them?

Global variables are those that are available throughout the length of the code, that is, these have no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.

Example:

// Declare a global globalVariable = "Test";

The problems that are faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.

 159 views

106⟩ Explain the for-in loop?

The for-in loop is used to loop through the properties of an object.

The syntax for the for-in loop is -

for (variable name in object){

statement or block to execute

}

In each repetition, one property from the object is associated to the variable name, and the loop is continued till all the properties of the object are depleted.

 130 views

107⟩ What is the difference between .call() and .apply()?

The function .call() and .apply() are very similar in their usage except a little difference. .call() is used when the number of the function's arguments are known to the programmer, as they have to be mentioned as arguments in the call statement. On the other hand, .apply() is used when the number is not known. The function .apply() expects the argument to be an array.

The basic difference between .call() and .apply() is in the way arguments are passed to the function. Their usage can be illustrated by the given example.

var someObject = {

myProperty : 'Foo',

myMethod : function(prefix, postfix) {

alert(prefix + this.myProperty + postfix);

}

};

someObject.myMethod('<', '>'); // alerts '<Foo>'

var someOtherObject = {

myProperty : 'Bar'

};

someObject.myMethod.call(someOtherObject, '<', '>'); // alerts '<Bar>'

someObject.myMethod.apply(someOtherObject, ['<', '>']); // alerts '<Bar>'

 151 views

108⟩ Define unescape() and escape() functions?

The escape () function is responsible for coding a string so as to make the transfer of the information from one computer to the other, across a network.

For Example:

<script>

document.write(escape("Hello? How are you!"));

</script>

Output: Hello%3F%20How%20are%20you%21

The unescape() function is very important as it decodes the coded string.

It works in the following way. For example:

<script>

document.write(unescape("Hello%3F%20How%20are%20you%21"));

</script>

Output: Hello? How are you!

 139 views

110⟩ What are Screen objects in JavaScript?

Screen objects are used to read the information from the client's screen. The properties of screen objects are -

► AvalHeight: Gives the height of client's screen

► AvailWidth: Gives the width of client's screen.

► ColorDepth: Gives the bit depth of images on the client's screen

► Height: Gives the total height of the client's screen, including the taskbar

► Width: Gives the total width of the client's screen, including the taskbar

 140 views

111⟩ How can JavaScript language be separated from objects?

JavaScript treats and creates the applications for the scripting to make the browser's compatible for use. The language is separated from the objects as it allows the syntax to change the environment. It is a language that keeps the page element in the HTML document. JavaScript allows the elements of the page to remain in sync with the document objects. The language is used to create objects that are connected to page elements and other elements in a language. The separation allows the concept of development and effort to be shared with each factor. The JavaScript language allows dynamic data to be presented using the weakly typed language. It also support any action to be taken to support user interface and graphics.

 125 views

112⟩ Why is object naming important to use in JavaScript?

- Object naming is used to create script references to objects while assigning names to every scriptable object in the HTML code. The browsers that are script compatible looks for the optional tags and attributes that enables the assigning of a unique name to each object. The example is :

<form name="dataEntry" method=get>

<input type="text" name="entry">

<frame src="info.html" name="main">

- The names act as a nametags through which the elements can be easily identified and easily located by the browsers. The references made for each object includes the object hierarchy from the top down. References are used to include names of each object that are coming in the window object. The object naming conventions are easy way to loacte the objects and the linking between them can be done more comfortably.

 140 views

113⟩ 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?

A script on this page is causing Internet Explorer to run slowly.

If it continues to run, your computer might become unresponsive.

 140 views

114⟩ 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";

oRequest.open("GET",sURL,false);

oRequest.setRequestHeader("User-Agent",navigator.userAgent);

oRequest.send(null)

if (oRequest.status==200) alert(oRequest.responseText);

else alert("Error executing XMLHttpRequest call!");

 147 views

119⟩ Write about the errors shown in JavaScript?

JavaScript gives a message if it encounters an error. The recognized errors are -

► Load-time errors: The errors shown at the time of the page loading are counted under Load-time errors. These errors are encountered by the use of improper syntax, and thus are detected while the page is getting loaded.

► Run-time errors: This is the error that comes up while the program is running. It is caused by illegal operations, for example, division of a number by zero, or trying to access a non-existent area of the memory.

► Logic errors: It is caused by the use of syntactically correct code, which does not fulfill the required task. For example, an infinite loop.

 152 views

120⟩ What is the use of DOM?

DOM is also known as Document Object Model which is used to develop a model with documents or web pages containing objects like elements, links, etc. These objects can be manipulated or certain actions like add, delete or change of an element can be performed using this document object model. Through this change in attributes can be done to get all the list of all the elements in the document. The DOM model responds to API calls that result in documented level of DOM recommendation. It is used to support additional behavior on the web page and use of API give an extensible advantage over other models existing. DOM codes are reused to meet the requirement of the real world and to make all the program interoperable.

 140 views