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

161⟩ Explain the role of deferred scripts in JavaScript?

By default, the parsing of the HTML code, during page loading, is paused until the script has not stopped executing. It means, if the server is slow or the script is particularly heavy, then the webpage is displayed with a delay. While using Deferred, scripts delays execution of the script till the time HTML parser is running. This reduces the loading time of web pages and they get displayed faster.

 246 views

162⟩ Explain with an example the use of event handlers in JavaScript?

The events in JavaScript are the actions in a document that result from user activity. The actions are like clicking on a button or typing a character in the form. JavaScript object in a document that receives events of different kinds. To handle the events that are taking place requires an even handler that can handle the execution of the events. Event acts like an added attribute that is entered in object's HTML. The attribute is consisting of event name, sign like (=), instructions. The following code shows the event handler as :

<HTML>

<BODY>

<FORM>

<INPUT TYPE="button" VALUE="Hello" onClick="window.alert ('HELLO WORLD')">

</FORM>

</BODY>

</HTML>

 241 views

164⟩ What are Math Constants and Functions using JavaScript?

► Math object has two constant : Math.PI and Math.E

► Math object has following functions :

Math.abs(val1); :It will give absolute value of val1.

Math.max(val1,val2); :This fuction will return maximum value from val1 and val2.

Math.random(); :This function will return a random number between 0 and 1.

Math.floor(val1) :This function will returns decimal value of val1.

 260 views

165⟩ What is Strict Mode in JavaScript?

► The fifth edition of ECMAScript specification has introduced Script Mode.

► Strict Mode applies a layer of constraint on JavaScript.

► It throws errors for actions that are problematic and didn't throw an error before.

► It throws errors for the actions which are potentially unsafe.

► It shut downs the functions which are poorly thought out.

► Strict mode solves mistakes that are responsible for the difficulty of JavaScript engines to perform optimizations.

► To enable the strict mode we have to add the string literal "use strict" on the top of file or function as follow :

function myfunction()

{

"use strict";

var v = "I am a strict mode function";

}

 248 views

166⟩ What are your favorite JavaScript libraries?

This is one of those general open-ended questions interviewers love to throw out. The only correct answer here is one that shows you're familiar with and have an opinion on the various JavaScript libraries. You could discuss the pros and cons of using raw JavaScript vs. jQuery, or describe an instance in which you'd use one library over another. Visit jsdb.io for a complete rundown.

 221 views

170⟩ 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.:

document.onclick=clickHandler;

document.onkeydown=keyHandler;

 238 views

171⟩ What is decodeURI() function?

► The decodeURI() function is used to decode the URI.

► Syntax :

decodeURI(uri)

Where uri is URI to be decoded

► For example :

<script>

var uri = "EmpDetails.asp?Emp=årpit&mode=edit";

document.write(encodeURI(uri) + "

");

document.write(decodeURI(uri) + "

");

</script>

► Output :

EmpDetails.asp?Emp=%C3%A5&mode=edit

EmpDetails.asp?Emp=årpit&mode=edit.

 228 views

172⟩ What is encodeURI() function?

► encodeURI() function is used to encode the URI.

► This function does not encode following special characters :

' = , ? : $ @ / & # + '

► Syntax : encodeURI(uri), Where uri is URI to be encoded.

► For example :

<script>

var uri = "EmpDetails.asp?Emp=årpit&mode=edit";

document.write(encodeURI(uri) + "

");

</script>

Output :

EmpDetails.asp?Emp=%C3%A5&mode=edit.

 220 views

174⟩ How can JavaScript codes be hidden from old browsers that don't support JavaScript?

For hiding JavaScript codes from old browsers:

Add "<!-" without the quotes in the code just after the <script> tag.

Add "//->" without the quotes in the code just before the <script> tag.

Old browsers will now treat this JavaScript code as a long HTML comment. While, a browser that supports JavaScript, will take the "<!-" and "//->" as one-line comments.

 216 views

176⟩ What does the isNaN() function do?

The isNaN() function is used to determine whether a value is not a number, or an illegal number. If the argument is not a number, the isNaN() function will return TRUE.

 220 views

177⟩ What would "1"+2+3 and 1+2+"3" evaluate to, respectively?

When the first character is a string, the remaining characters will be converted into a single string, rendering 123.

If the string is at the end, the initial characters will perform normal mathematical functions before converting into a string, resulting in 33.

 224 views

178⟩ What is the difference between Scripting and Programming?

- Scripting is easier to write than programming. As programming requires more hands on to the code and a language specification to write.

- Scripting consists of lots of tools to easily create an object model and run it using any browser, wheras programming doesn't have many tools to create an object model and it is not easy to use browser compatibility.

- Scripts work with more than just objects, each statement of the JavaScript does something means perform some actions, whereas programming becomes different as each and every action takes time to execute.

- Scriptting doesn't require lots of knowledge to be provided with and can be easily learnt, but to learn a programming language it requires lots of knowledge.

 233 views

179⟩ What is the disadvantages using innerHTML in JavaScript?

► If you use innerHTML the content is replaced everytime.

► We cannot use like 'appending to innerHTML'.

► Even if we use += like "innerHTML = innerHTML + 'html'" then also the old content is replaced by html.

► If we use innerHTML then the entire innerHTML content is re-parsed and build into elements. Therefore it's much slower.

► The innerHTML doesn't provide validation and therefore we can potentially insert invalid and broken HTML in the document and break it.

 231 views