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

181⟩ Explain what is pop()method in JavaScript?

The pop() method is similar as the shift() method but the difference is that the Shift method works at the start of the array. Also the pop() method take the last element off of the given array and returns it. The array on which is called is then altered.

Example:

var cloths = ["Shirt", "Pant", "TShirt"];

cloths.pop();

//Now cloth becomes Shirt,Pant

 236 views

182⟩ 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;}

window.onerror=handlerFunction;

 217 views

183⟩ What is difference between undefined variable and undeclared variable?

► The variable which are declared in the program but not assigned any value yet is called undefined variable while the variable which are not declared in the program is called undeclared variable.

► For Example :

undeclared variable:

<script>

var p;

alert(p); // This will give error because p is undeclared variable.

</script>

? undefined variable

<script>

alert(p); //This will give error because p is undefined.

</script>

 211 views

184⟩ What is JavaScript, what about history?

JavaScript, some also know it as ECMAScript, is a dynamic programming language used in a web development. It is an integral part of web browsers, and it allows, among other things, better user interaction, browser control, client-server communications (synchronous and asynchronous), alterations of displayed DOM content.

Although it was first introduced under a different name (Mocha), during its initial release it was officially named LiveScript. Developed by Netscape, the first version was available in Navigator 2.0 (September 1995), but it was renamed JavaScript in version 2.0B3.

 247 views

185⟩ What is escape() function?

► The escape() function is used to encode the string to convert it as portable string so that it can be sent across any network to any computer which supports ASCII characters.

► This function encodes special characters, with the exception of @ * + - / . _

► Syntax :

escape(string1)

Where string1 is the string to be encoded.

► Example :

<script>

document.write(escape("Questions? Get from us!"));

</script>

► Output :

Questions%3F%20Get%20from%20us%21

 212 views

186⟩ What are the different types of errors in JavaScript?

There are three types of errors:

► Load time errors: Errors which come up when loading a web page like improper syntax errors are known as Load time errors and it generates the errors dynamically.

► Run time errors: Errors that come due to misuse of the command inside the HTML language.

► Logical Errors: These are the errors that occur due to the bad logic performed on a function which is having different operation.

 228 views

187⟩ 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

}

 225 views

188⟩ What does a timer do and how would you implement one?

Setting timers allows you to execute your code at predefined times or intervals.

This can be achieved through two main methods: setInterval(); and setTimeout();

setInterval() accepts a function and a specified number of milliseconds.

ex) setInterval(function(){alert("Hello, World!"),10000) will alert the "Hello, World!" function every 10 seconds.

setTimeout() also accepts a function, followed by milliseconds. setTimeout() will only execute the function once after the specified amount of time, and will not reoccur in intervals.

 228 views

189⟩ What is Push() method in JavaScript?

► The push() method is used to append one or more elements to the end of an array.

► For example :

var fruits = [ "apple" ];

fruits.push( "banana" );

fruits.push( "mango", "strawberry" );

console.log(fruits);

► We get the following console output :

["apple ", "banana ", "mango ", "strawberry "]

► Using Push() method we can also append multiple elements by passing multiple arguments.

► The elements will be appended in the order of they are inserted i.e. left to right.

 235 views

192⟩ Why would you include 'use strict' at the beginning of a JavaScript source file?

Using strict mode enforces stricter error handling when running your code. It essentially raises errors that would have otherwise failed silently. Using strict mode can help you avoid simple mistakes like creating accidental globals, undefined values, or duplicate property names. This is typically a good idea when writing JavaScript, as such errors can create a lot of frustrating side effects and be difficult to track down.

 208 views

193⟩ What is the function of Deferred scripts?

Deferred scripts are the scripts whose statements run as grouped together statements as a function. Function provides a definition of a block that a script statement consists of to run the statements that are in the <SCRIPT> tags after all the statements loaded in the browser. Functions allow to see the user clearly the visiblity inside the <SCRIPT> tag. In this tag each function starts with function() and function name is written after it including the parentheses. Once a function is loaded it becomes ready to run whenever there is a use of it. It is useful when a function gets used immediately after a page load. The Window object uses an event handler that triggers the response to the user actions and the handler is onLoad.

 221 views

194⟩ What is Shift() method in Javascript?

► The shift() method is similar as the pop() method but the difference is that Shift method works at the beginning of the array.

► The shift() method take the first element off of the given array and returns it. The array on which is called is then altered.

► For example :

var myarray = ["apple ", "banana ", "mango "];

console.log(myarray.shift());

console.log(myarray);

► We get the following console output :

apple

["banana ", "mango "];

► When we call shift() on an empty array, it will return an undefined value.

 215 views

195⟩ What is Screen object?

► The screen object can be used to retrieve the information about the visitor's screen.

► There are following properties of Screen objects :

avalHeight : This property returns the height of the screen excluding the windows taskbar.

availWidth : This property returns the width of the screen excluding the windows taskbar.

colorDepth : This property returns the bit depth of the color palette to display images.

height : This property returns the total height of the screen.

pixelDepth : This property returns the color resolution of the screen in bits per pixel.

width : This property returns the total width of the screen.

 219 views

196⟩ Is JavaScript case sensitive?

Yes, absolutely. For example, the function getElementById is not the same as the function getElementbyID. Keeping your capitalization consistent is important.

 212 views

197⟩ What is the difference between script type and the script language attributes?

► The script type specifies the type of content that is used to show the language used by the browsers like "language=text/javascript". This defines the MIME type that is also known as Multipurpose Internet Mail Extensions (MIME). Text in this defines a plain text format and script defines the language that will be used.

► The script language attribute on the other hand specify a particular version of JavaScript language that is required to run the script and to provide a mechanism to fall back if any browser doesn't support it.

► Script type is used to define the type through which the browser can understand the language and all the compatible browsers can execute the type according to themselves, whereas the script language attribute defines the content and its attributes that are used.

 225 views

199⟩ What is NaN in JavaScript?

Nan is literally "Not-a-Number". NaN usually results when either the result or one of the values in an operation is non-numeric. Even though NaN is not a number, 'console.log(typeof NaN === "number");' logs true, while NaN compared to anything else (including NaN) logs false. The only real way to test if a value is equal to NaN is with the function 'isNaN()'.

 246 views