Top 40 Javascript Interview Questions and Answers
Top 40 Javascript Interview Questions and Answers
JAVASCRIPT
TOP 40 MCQ'S WITH ANSWERS
www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
1. What are the three important manipulations done in for loop on a loop variable?
a) Updation, Incrementation, Initialization
b) Initialization,Testing, Updation
c) Testing, Updation, Testing
d) Initialization,Testing, Incrementation
Explanation: In for loop, firstly the loop initializes the variable then test the condition and then
after executing the statement increments its value.
Explanation: An invocation expression is JavaScript’s syntax for calling (or executing) a function
(or method). It starts with a function expression that identifies the function to be called.
Explanation: If the script tag is placed after the body tag, then, it will not be evaluated at all.
Also, it is always recommended and effective to use the script snippet in the <head> tag.
Page 1 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
Explanation: A class mainly contains data members and associated member functions.
Therefore over all different kinds of class members are instance field, instance method, class
fields and class methods.
Explanation: The scope of a function can be used as a private namespace for a module.
Therefore, the scope of a function is called a module function.
8. The regular expression to match any one character not between the brackets is:
a) […]
b) [^]
c) [^…]
d) [\D]
Explanation: RegExp defines a special set of character that is used to do manipulation on strings
Page 2 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
and other variables. The [^…] character class is used to match or draw any one character not
between the brackets.
Explanation: There are two classes of events one is called event listener and the other is called
event emitter. Node objects that generate events (known as event emitters) define an on()
method for registering handlers.
Explanation: The process object is an event emitter. The Node defines other important globals
under the process namespaces that contain properties of that object like version, argv, env, pid,
getuid(), cwd(), chdir() and exit().
Explanation: To retrieve a value, pass the name to getItem(). The getItem() method of the
Storage interface, when passed a key name, will return that key’s value, or null if the key does
not exist, in the given Storage object.
Page 3 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
Explanation: Data events are the events which are performed by either the user or the
browser.
13. Which is the handler method used to invoke when uncaught JavaScript exceptions
occur?
a) Onhalt
b) Onerror
c) Both onhalt and onerror
d) Onsuspend
Explanation: The onerror handler method can be registered to be invoked when uncaught
JavaScript exceptions occur. The onerror event is triggered if an error occurs while loading an
external file (e.g. a document or an image).
Explanation: The paragraph tag belongs to both html and body tag. It is used to write
paragraph on html pages.
Explanation: The Document object has a URL property, which is a static string that holds the
URL of the document when it was first loaded. If you want to access any element in an HTML
page, you always start with accessing the document object.
Page 4 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
b) Selectors
c) Both Protectors and Selectors
d) Protectors or Selectors
Explanation: CSS style sheets have a very powerful syntax, known as selectors, for describing
elements or sets of elements within a document
Explanation: Web pages include images using the HTML img element. src tag is used to include
the image link.
Explanation: When the amount of JavaScript code is so large that it effectively obscures the
HTML, we call JavaScript as obtrusive.
Explanation: The HTML canvas element is used to draw graphics, on the fly, via JavaScript. The
canvas element is only a container for graphics. The canvas element has no appearance of its
own but creates a drawing surface within the document and exposes a powerful drawing API to
client-side JavaScript.
Page 5 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
Explanation: SVG stands for ‘Scalable Vector Graphics’ and it is used to define graphics for the
Web. SVG is mostly used for vector type diagrams like Two-dimensional graphs in an X, Y
coordinate system, Pie charts etc. SVG describes complex shapes as a “path” of lines and curves
that can be drawn or filled.
21. What does the handshake pass between the browser and the remote server?
a) Synchronize
b) Accept
c) Reject
d) Decline
Explanation: The handshake allows the server to acknowledge and accept the attempt. The
handshake consists of a Synchronize, Synchronize-Acknowledge, and Acknowledge message to
be passed between the browser and the remote server.
Page 6 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
Explanation: Minifying JavaScript results in decreasing the loading time and hence helps in
creating a better user experience.
Explanation: Just like Minify, YUI Compressor strips out all of the unnecessary characters from
your JavaScript, including spaces, line breaks, and comments.
Explanation: JavaScript supports external JavaScript, in the form of .js file. This extension can
be captured by a number of applications including: Windows Script Host, Dreamweaver MX,
Notepad, Netscape Navigator, PavScrip, UltraEdit.
Page 7 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
Explanation: Any object inside the timer will hold a reference in order to run that piece of code
somewhere in the future without any problems. One particularly obscure way to retain an
object in memory is to log it to the console.
29. What will happen if the browser encounters a script tag without src attribute?
a) Throws an error
b) Throws an exception
c) Sends it to the compiler
d) Sends it to the interpreter
Explanation: If the browser encounters a script tag without src attribute, the rendering engine
simply passes the code to the JavaScript Interpreter for execution. The src attribute specifies
the location (URL) of the external resource.
Explanation: The type of script_url can be anything that will be compared with the typeof
keyword’s result. The src attribute specifies the location (URL) of the external resource.
Page 8 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
a) window.reload
b) location.reload
c) window.refresh
d) page.refresh
Explanation: The reload() method is used to reload the current document. The reload() method
does the same as the reload button in your browser. One can refresh the webpage in JavaScript
by using location.reload.
32. How many constant values can the property type be represented?
a) 2
b) 3
c) 4
d) 5
Explanation: The type property sets or returns the value of the type attribute of an <object>
element. The type attribute specifies the Internet media type of the object. Totally 4 constant
values can be represented by the property type.
Explanation: A heap is a tree-like data structure where each node must be ordered with respect to the
value of its children. The heap is the collection of JavaScript objects that the interpreter keeps in
resident memory.
Page 9 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
Explanation: Array is defined with a null value when no value is mentioned. If you omit a value
from an array literal, the omitted element is given an undefined value.
Explanation: Functions generally have a return statement and hence usually returns a value.
Some functions which do not have a return statement returns value by default during
execution.
Explanation: The main advantage of using the src attribute is that it simplifies your HTML files
by allowing you to remove large blocks of JavaScript code from them. Hence separate files for
css and javascript files are made to make the code modular and readable.
37. What will be done if more than one page requires a file of JavaScript code?
a) Downloads that many times
b) Retrieves from the browser cache
c) Must be re executed
d) Must be included in all the pages
Explanation: If a file of JavaScript code is shared by more than one page, it only needs to be
downloaded once, by the first page that uses it—subsequent pages can retrieve it from the
browser cache. This makes the loading process easier and hence faster.
Page 10 of 11 www.mobiprep.com
TOP 40 JAVASCRIPT MCQ’s WITH ANSWERS
a) Client
b) Server
c) Both Client and Server
d) User side
Explanation: The data information from the client side is first sent to the server side. Form
validation used to occur at the server after the client had entered all necessary data and then
pressed the Submit button.
Explanation: The data entered through the server side is used for validation. The data that is
entered must be checked for correct form and value. This would need to put more logic to test
the correctness of data.
Page 11 of 11 www.mobiprep.com