Link Search Menu Expand Document

TOP-10 Most Asked JavaScript Coding Questions

Here is a list of most asked JavaScript coding questions. It contains queries from simple to advanced.

Q1. What is the negative infinity in JavaScript?

Ans. Negative infinity in JavaScript represents a constant value, which is the lowest available. Thus, no other number can be lower than negative infinity; to achieve this, divide a negative number with zero.

Q2. Can JavaScript code be broken into several lines?

Ans. Yes. You can break a JavaScript code into several lines using a Backslash ‘\’at the end of the first line. Example:

document.write(“This is \a question”) ;

If any attempts are made to move to a new line without using a string statement, then JavaScript ignores any break in the line.

Example:
var x=3, y=7
z=
x+y;

Although this code will work, it can create problems while debugging.

Q3. What is the use of a prompt box?

Ans. A prompt box enables the user to enter input by providing a text box on a user interface. A label and a designated box are given so that text or a number can be added.

Q4. What do timers do in JavaScript? Are there any negative repercussions for using the timer?

Ans. While executing code at a given time or repeat the code in separate time windows, timers are used. The functions that make it possible setTimeout, setInterval and clearInterval. The setTimeout(function, delay) function can begin a timer that brings up a respective function after the set delay. The setInterval(function, delay) function is used to execute a particular function on repeat in the mentioned delay and only stops when it gets canceled. The clearInterval(id) function orders the timer to stop. Timers are used inside a single thread, making events wait in the queue to be executed in a particular order.

Q5. For comments in JavaScript, which symbol is used?

Ans. For single-line comments, // is used in front of the code or text so that the JavaScript interpreter would ignore it.

For multi-line comments, you use this:
/* This
Is
An
Example
*/

Q6. State the differences between Viewstate and SessionState?

Ans. The basic difference between a Viewstate and Sessionstate is that Viewstate is information specific to a particular webpage. A Sessionstate, on the other hand, contains information that is in particular for a specific session by a particular client, or a browser, or a machine within the server.

Q7. Explain how can a form be submitted using JavaScript?

Ans. In order to submit a form using JavaScript use document.form[0].submit();

Q8. Is automatic type conversion supported by JavaScript?

Ans. Yes, Javascript does support automatic type conversion. It is commonly used by JavaScript developers for conversion.

Q9. State all the looping structures available in JavaScript.

Ans. Here are all the looping structures in JavaScript:

  1. for
  2. while
  3. do-while loops

Q10. Can you convert the string of any base to integer in JavaScript?

Ans. Yes, the function used to convert numbers within different bases is parseInt(). The first parameter parseInt() takes for the conversion is the string, and the second parameter is the base of the given string.

To convert 4F (of base 16) to an integer, the following code can be used
parseInt (“4F”,16)

Practice these basic to advanced questions to improve your knowledge of JavaScript.

Other useful articles:


Back to top

© , Study JavaScript — All Rights Reserved - Terms of Use - Privacy Policy