Tricky Expert Developer JavaScript Interview Preparation Guide
Download PDF

Expert Developer JavaScript Frequently Asked Questions by expert members with experience in Expert JavaScript Developer. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts

150 Expert JavaScript Developer Questions and Answers:

Table of Contents:

Tricky  Expert JavaScript Developer Job Interview Questions and Answers
Tricky Expert JavaScript Developer Job Interview Questions and Answers

1 :: Can you use x === "object" to test if x is an object?

In short, yes, but you must take into account the fact that null is considered an object in JavaScript. Even if x is null, 'console.log(typeof x === "object")' will log true instead of false.
To account for this, you must also test whether or not x is null by including the following:
console.log((x !== null) && (typeof x === "object"));

2 :: What happens when you don't declare a variable in Javascript?

If you don't explicitly declare a variable, you risk creating an implied global variable. This is a problem, as you will be unable to create multiple instances of that object, as each new instance will overwrite the data from the last.
In general, global variables should be used only in very specific situations and are typically not recommended, as they can lead to a lot of odd side effects that may be difficult to track down.

3 :: 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.

4 :: Explain the concept of unobtrusive JavaScript?

Unobtrusive JavaScript is basically a JavaScript methodology that seeks to overcome browser inconsistencies by separating page functionality from structure. The basic premise of unobtrusive JavaScript is that page functionality should be maintained even when JavaScript is unavailable on a user's browser.

5 :: 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.

6 :: What is namespacing in JavaScript and how is it used?

Namespacing is used for grouping the desired functions, variables etc. under a unique name. It is a name that has been attached to the desired functions, objects and properties. This improves modularity in the coding and enables code reuse.

7 :: 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()'.

8 :: What is unescape() function?

► The unescape() function is used to decode the encoded string.
► Syntax : unescape(string1)
► Where string1 is the string to be decoded.
► Example :
<script>
document.write(unescape("Questions%3F%20Get%20from%20us%21"));
</script>
- Output :
Questions? Get from us!
ECMAScript is nothing but another name for JavaScript. Precisely, ECMAScript is the formal name of JavaScript, when XML elements have to be accessed.

10 :: Which boolean operators are in JavaScript?

'and' operator: &&
'or' operator: ||
'not' operator: !

11 :: What is the difference between window.onload and onDocumentReady?

► The difference is that onDocumentReady is called after the DOM is loaded without waiting for all the contents to get loaded. While window.onload() function waits until the contents of page is loaded.
► Suppose there is very large image on a page, at that time onDocumentReady will wait until that image is loaded totally.
► So while using the window.onlaod() function the execution will be slow, but the onDocumentReady will not wait until the image is loaded.

12 :: What is the method for reading and writing a file in JavaScript?

This can be done by Using JavaScript extensions (runs from JavaScript Editor), example for opening of a file -

fh = fopen(getScriptPath(), 0);

13 :: 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.

14 :: 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.
This can be done by including the name of the required frame in the hyperlink using the 'target' attribute.

<a href="newpage.htm" target="newframe">>New Page</a>

16 :: 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.

17 :: 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.

18 :: 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.

19 :: What is the difference between JavaScript and JScript?

Both are almost similar. JavaScript is developed by Netscape and Jscript was developed by Microsoft.

20 :: 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.

21 :: 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.

22 :: 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
}

23 :: 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.

24 :: 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.

25 :: 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
Expert JavaScript Developer Interview Questions and Answers
150 Expert JavaScript Developer Interview Questions and Answers