Javascript MCQ Questions
Javascript MCQs :
This section focuses on javascript mcq. These Multiple Choice Questions should be practiced to improve the Javascript skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which of the following is not JavaScript Data Types?
A. Undefined
B. Number
C. Boolean
D. Float
View Answer
Ans : D
Explanation: Following are the JavaScript Data types:
Number
String
Boolean
Object
Undefined
2. Which company developed JavaScript?
A. Netscape
B. Bell Labs
C. Sun Microsystems
D. IBM
View Answer
Ans : A
Explanation:Netscape is the software company who developed JavaScript.
3. Inside which HTML element do we put the JavaScript?
A. <script>
B. <head>
C. <meta>
D. <style>
View Answer
Ans : A
Explanation: <script> is the element where we put the javascript.
4. Which of the following is correct about features of JavaScript?
A. It can not Handling dates and time.
B. JavaScript is a object-based scripting language.
C. JavaScript is not interpreter based scripting language.
D. All of the above
View Answer
Ans : B
Explanation: Some features of javascripts are as follow:-
1. JavaScript is a object-based scripting language.
2. Giving the user more control over the browser.
3. It Handling dates and time.
4. It Detecting the user's browser and OS,
5. It is light weighted.
6. JavaScript is a scripting language and it is not java.
7. JavaScript is interpreter based scripting language.
8. JavaScript is case sensitive.
5. Choose the correct JavaScript syntax to change the content of the following HTML code.
A. document.getElement ("letsfindcourse").innerHTML = "I am a letsfindcourse";
B. document.getElementById ("letsfindcourse").innerHTML = "I am a letsfindcourse";
C. document.getId ("letsfindcourse") = "I am a letsfindcourse";
D. document.getElementById ("letsfindcourse").innerHTML = I am a letsfindcourse;
View Answer
Ans : B
Explanation:The correct syntax to access the element is document.getElementById("letsfindcourse"). Here we want to access the content written under that id, so we used .innerHTML to specify that and finally we replaced the content with whatever is written inside the quotes.
6. Which of the following are advantages of JavaScript?
A. Less server interaction
B. Increased interactivity
C. Richer interfaces
D. All of the above
View Answer
Ans : D
Explanation:The merits of using JavaScript are : Less server interaction, Immediate feedback to the visitors, Increased interactivity and Richer interfaces.
7. Which of the following true about Javascript?
A. Client-side JavaScript does not allow the reading or writing of files
B. JavaScript cannot be used for networking applications
C. JavaScript doesn't have any multi-threading or multiprocessor capabilities
D. All of the above
View Answer
Ans : D
Explanation:All of the above are true statement about Javascript.
8. Microsoft has developed a popular HTML editor called?
A. Dreamweaver
B. FrontPage
C. HomeSite
D. Macromedia
View Answer
Ans : B
Explanation:Microsoft has developed a popular HTML editor called FrontPage. FrontPage also provides web developers with a number of JavaScript tools to assist in the creation of interactive websites.
9. HomeSite 5 is a well-liked HTML and JavaScript editor from Macromedia.
A. True
B. False
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation:True, HomeSite 5 is a well-liked HTML and JavaScript editor from Macromedia.
10. JavaScript ignores?
A. spaces
B. tabs
C. newlines
D. All of the above
View Answer
Ans : D
Explanation:JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs. You can use spaces, tabs, and newlines freely in your program and you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand.
11. JavaScript is designed for following purpose -
A. to style HTML pages
B. to execute Queries related to databases on a server
C. to add interactivity to html pages
D. All of the above
View Answer
Ans : D
Explanation: JavaScript is designed for the following purpose: to style HTML pages b. to execute Queries related to databases on a server c. to add interactivity to html pages d. to perform server side scripting operations e. none of the above JavaScript statements are terminated by a a.
12. What will be the output of the following Javascript code?
var string1 = "Letsfindcourse";
var intvalue = 30;
alert( string1 + intvalue );
A. Letsfindcourse 30
B. 30
C. Letsfindcourse30
D. Exception
View Answer
Ans : C
Explanation:In JavaScript the alert function does the type casting and converts the integer value to string. After that it concatenates both the strings and shows the result as a concatenated string. Thus Letsfindcourse30 would be correct.
13. Among the following, which one is a ternary operator in JavaScript?
A. #
B. ::
C. &:
D. ?:
View Answer
Ans : D
Explanation: JavaScript supports one ternary operator, the conditional operator ?:, which combines three expressions into a single expression. If else case can be replaced by the conditional operator
14. What are the three important manipulations done in a for loop on a loop variable in javascript?
A. the initialization, the Incrementation, and update
B. the initialization, the test, and the update
C. the initialization, the test, and Incrementation
D. All of the above
View Answer
Ans : B
Explanation: In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable. Firstly the loop initialiases the variable then test the condition and then after executing the statement increments its value.
15. What does javascript use instead of == and !=?
A. It uses bitwise checking
B. It uses === and !== instead
C. It uses equals() and notequals() instead
D. It uses equalto()
View Answer
Ans : B
Explanation:The subset does not include the comma operator, the bitwise operators, or the ++ and — operators. It also disallows == and != because of the type conversion they perform, requiring use of === and !== instead.
16. What should appear at the very end of your JavaScript?
The <script language="javascript"> tag
A. <script>
B. <script>
C. </script language="javascript">
D. All of the above
View Answer
Ans : B
Explanation: </script> Should appear at the very end of your JavaScript.
The < script> element either contains scripting statements, or it points to an external script file through the src attribute.
17. Among the keywords below, which one is not a statement?
A. if
B. with
C. debugger
D. use strict
View Answer
Ans : D
Explanation:use strict is a directive introduced in ECMAScript5. Directives are not statements because it does not include any language keywords. Also, it can appear only at the start of a script or at the start of a function body, before any real statement has appeared.
18. How do we define the term Thread?
A. Device that controls input
B. Variable that controls movement
C. Controlled execution of applications
D. None of the above
View Answer
Ans : C
Explanation: Javascript is single-threaded. To clarify better, this means that one single thread handles the event loop. For older browsers, the whole browser shared one single thread between all the tabs.
19. Which symbol is used for comments in Javascript?
A. \\
B. //
C. \* *\
D. \* */
View Answer
Ans : B
Explanation: Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript
20. Which of them is not the looping structures in JavaScript?
A. for
B. while
C. forwhich
D. dowhile
View Answer
Ans : B
Explanation:forwhich is not the looping structures in JavaScript
21. What is defination of an undefined value in JavaScript?
A. Variable used in the code doesn't exist
B. Variable is not assigned to any value
C. Property doesn't exist
D. All of the above
View Answer
Ans : D
Explanation:Undefined value means the
1.Variable used in the code doesn't exist
2.Variable is not assigned to any value
3.Property doesn't exist
22. What are the types of Pop up boxes available in JavaScript?
A. Alert
B. Prompt
C. Confirm
D. All of the above
View Answer
Ans : D
Explanation: the types of Pop up boxes available in JavaScript
1. Alert
2. Confirm and
3. Prompt
23. what is the disadvantage of using innerHTML in JavaScript?
A. Content can not be replaced everywhere
B. We can use like "appending to innerHTML"
C. Even if you use +=like "innerHTML = innerHTML + 'html'" still the old content is replaced by html
D. The entire innerHTML content is not re-parsed and build into elements, therefore its not slower
View Answer
Ans : C
Explanation: If you use innerHTML in JavaScript the disadvantage is
1.Content is replaced everywhere
2.We cannot use like "appending to innerHTML"
3.Even if you use +=like "innerHTML = innerHTML + 'html'" still the old content is replaced by html
4.The entire innerHTML content is re-parsed and build into elements, therefore its much slower
5.The innerHTML does not provide validation and therefore we can potentially insert valid and broken HTML in the document and break it.
24. What are the two basic groups of dataypes in JavaScript?
A. Primitive
B. Reference types.
C. All of the above
D. None of the above
View Answer
Ans : C
Explanation: They are as –
Primitive
Reference types.
Primitive types are number and Boolean data types. Reference types are more complex types like strings and dates.
25. Which of the following are the errors in JavaScript?
A. Load time errors
B. Run time errors:
C. Logical Errors:
D. All of the above
View Answer
Ans : B
Explanation:There are three types of errors:
Load time errors: Load-time errors are perhaps the most common and are generally caused by problems in syntax.
Run time errors:A runtime error is a program error that occurs while the program is running.
Logical Errors: A logic error (or logical error) is a mistake in a program's source code that results in incorrect or unexpected behavior.
26. Which of the following are the functional components in JavaScript?
A. First-class functions
B. Encapsulated-class functions
C. Fixed-class functions
D. All of the above
View Answer
Ans : A
Explanation:The different functional components in JavaScript are-
1. First-class functions
2. Nested functions
27. Which of the following is not the properties of screen objects in JavaScript?
A. AvailHeight
B. ColorsDepth
C. AvailWidth
D. ColorDepth
View Answer
Ans : B
Explanation:Screen objects are used to read the information from the client's screen. The properties of screen objects are -
1. AvailHeight
2. AvailWidth
3. ColorDepth
4. Width
5. Height
28. Javascript string using double quotes is exactly the same as a string using single quotes?
A. True
B. False
View Answer
Ans : A
Explanation: True is the answer
29. Find output of below code
var a = '20';
var b = a = 30;
document.write(a+b);
A. Error in Script
B. '20'30
C. 2030
D. 50
View Answer
Ans : D
Explanation: No explanation.
30. What is divide by 0 in Javascript?
var a = 10;
var b = 0;
document.write(a/b);
A. Nothing is printed
B. 0 is printed
C. Infinity is printed
D. Some Garbage Value
View Answer
Ans : C
Explanation:Infinity is printed divide by 0 in Javascript
31.Which of the following function of Array object applies a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value?
A - pop()
B - reduce()
C - push()
D - reduceRight()
View Answer
Ans : D
Explanation:reduceRight() − Applies a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
32. What is the output of following Javascript?
var a = 'letsfind';
var b = 'course';
var c = a/b;
document.write(c);
A. letsfindcourse
B. letsfind/course
C. NaN
D. None of the above
View Answer
Ans : C
Explanation: he output of following Javascript is NaN.
33. How ++ works in Javascript? Find output of below Javascript code.
var a = 1;
document.write(a--);
document.write(a);
A. 00
B. 01
C. 11
D. 10
View Answer
Ans : D
Explanation: document.write(a--); will print 1 and after than it will decrement the variable a value to 0 , next line document.write(a); will print 0.
34. Find output of below Javascript addition code
document.write("1 plus 1 is " + 1 + 1);
A. 2
B. 1 plus 1 is 2
C. 1 plus 1 is 11
D. 1 plus 1 is 1 + 1
View Answer
Ans : C
Explanation:output of below Javascript addition code is 1 plus 1 is 11.
35.In JavaScript, Arrays are data type. State True or False
A. True
B. False
View Answer
Ans : B
Explanation:In JavaScript, Arrays is not data type.
JavaScript - The Arrays Object. The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type.
36. Does JavaScript allow exception handling?
A. Yes, it provides try, catch as well as throw key word for exception handling
B. Yes, but it provides only try block
C. Yes, but it provides only Try catch block, but does not allow throw exception
D. No
View Answer
Ans : A
Explanation:JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions. You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors.
37. Which of the following method checks if its argument is not a number?
A. isNaN()
B. nonNaN()
C. NaN()
D. None of the above
View Answer
Ans : A
Explanation:The Number.isNaN() method determines whether a value is NaN (Not-A-Number). This method returns true if the value is of the type Number, and equates to NaN. Otherwise it returns false.
38. What if you use parseInt() to convert a string containing decimal value?
A. Throws Error
B. It returns the decimal values in string form
C. If returns only the integer portion of the number
D. None of the listed option
View Answer
Ans : C
Explanation: JavaScript's parseInt function is all about converting a string to an integer. The function takes a string value as an argument and converts it to a numerical value with no decimal places, or alternatively the value NaN.
39. What is the output of below Javascript code?
alert (typeof new Date() );
A. Throws Error
B. object
C. Displays Nothing
D. Current Date
View Answer
Ans : B
Explanation: The typeof is an operator keyword which is used to get a type at the compile-time. Or in other words, this operator is used to get the System.Type object for a type.
40. What if we put ++ operator inside if condition? find the output of below code
<script>
var a = 10;
if(a == a++)
document.write(a);
</script>
A. Error
B. Nothing is printed
C. 10
D. 11
View Answer
Ans : D
Explanation:During initialization the value of variable a is 10.But after if condition it becomes 11 due to "a++" in if condition.
41.Which of the following is true?
A. If onKeyDown returns false, the key-press event is cancelled.
B. If onKeyPress returns false, the key-down event is cancelled.
C. If onKeyDown returns false, the key-up event is cancelled.
D. If onKeyPress returns false, the key-up event is canceled.
View Answer
Ans : A
Explanation:No explanation.
42. Syntax for creating a RegExp object:
1. var txt=new RegExp(pattern,attributes);
2. var txt=/pattern/attributes;
Which of the above mentioned syntax will correct?
A. 1 only
B. 2 only
C. Both 1 and 2
D. None of the above
View Answer
Ans : C
Explanation: Both the statement are correct.
Both the syntax can be used for creating a RegExp object.
43. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph?
A. para1="New Text"
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
View Answer
Ans : B
Explanation: the correct syntax to change the text within the paragraph is "para1.value="New Text";"
44. The syntax of Eval is ________________
A. [objectName.]eval(numeric)
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeric)
View Answer
Ans : B
Explanation:The eval() function evaluates or executes an argument. If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements.
45. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
View Answer
Ans : D
Explanation:The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object
46. Which tag(s) can handle mouse events in Netscape?
A. <IMG>
B. <A>
C. <BR>
D. <span>
View Answer
Ans : A
Explanation:The img element can handle mouse events in Netscape.
47. Consider the following code snippet
const pi=3.14;
var pi=4;
console.log(pi);
What will be the output for the above code snippet?
A. This will flash an error
B. Prints 4
C. Prints 3.14
D. Ambiguity
View Answer
Ans : A
Explanation: Const keyword fixes the value of the variable. Const keyword can not be redefined. Therefore attempts to alter the value or re-declaration causes errors.
48. What is the default value of the asyc attribute?
A. 0
B. 1
C. False
D. True
View Answer
Ans : D
Explanation: The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available. The async attribute optionally accepts a boolean value and by default holds the value true.
49. What is the purpose of the Attr object in the HTML DOM?
A. Used to focus on a particular part of the HTML page
B. HTML Attribute
C. Used to arrange elements
D. None of the mentioned
View Answer
Ans : B
Explanation: In the HTML DOM, the Attr object represents an HTML attribute.
50. Which among the following POSIX signals generate events?
A. SIGDOWN
B. SIGFLOAT
C. SIGINT
D. SIGSHORT
View Answer
Ans : C
Explanation:The SIGINT is a POSIX signal that generates event. A simple code like below can do a proper clean up and exit on CTRL-C or SIGINT passed from command line / other application to the nodejs app’s ProcessID.
51.Javascript is ideal to?
A. make computations in HTML simpler
B. minimize storage requirements on the web server
C. increase the download time for the client
D. none of the mentioned
View Answer
Ans : B
Explanation:Javascript helps in doing various tasks with minimum storage requirements. Therefore, to reduce storage requirements, Javascript has always said a better one. explanation.
52. The meaning for Augmenting classes is that:
A. objects inherit prototype properties even in dynamic state
B. objects inherit prototype properties only in dynamic state
C. objects inherit prototype properties in static state
D. object doesn't inherit prototype properties in static state
View Answer
Ans : A
Explanation:Javascript's prototype-based inherit system is dynamic: an object inherits properties with its prototype, even if the prototype changes after the creation of the object. This means that we can increase JavaScript classes by adding new methods only to their prototype objects.
53. Which is the handler method used to invoke when uncaught JavaScript exceptions occur?
A. Onhalt
B. Onerror
C. Both onhalt and onerror
D. Onsuspend
View Answer
Ans : B
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 .
54. Consider the code snippet given below
var count = [1,,3];
What is the observation made?
A. The omitted value takes "undefined"
B. This results in an error
C. This results in an exception
D. The omitted value takes an integer value
View Answer
Ans : A
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.
55. Which among the following POSIX signals generate events?
A. SIGDOWN
B. SIGFLOAT
C. SIGINT
D. SIGSHORT
View Answer
Ans : C
Explanation:The SIGINT is a POSIX signal that generates event. A simple code like below can do a proper clean up and exit on CTRL-C or SIGINT passed from command line / other application to the nodejs app’s ProcessID.
56. What does the interpreter do when you reference variables in other scopes?
A. Traverses the queue
B. Traverses the stack
C. Finds the bugs
D. Traverse the array
View Answer
Ans : B
Explanation:The interpreter executes the javascript code. Normally when you reference variables in other scopes at the global level, in other namespaces, and so on—the interpreter needs to traverse the stack to get to the variable.
57. What must be done in order to implement Lexical Scoping?
A. Get the object
B. Dereference the current scope chain
C. Reference the current scope chain
D. Return the value
View Answer
Ans : C
Explanation: In order to implement lexical scoping, the internal state of a JavaScript function object must include not only the code of the function but also a reference to the current scope chain.
58. From which version of IE is canvas supported?
A. 6
B. 7
C. 8
D. 9
View Answer
Ans : D
Explanation: The canvas element is not supported by IE before IE9, but it can be reasonably well emulated in IE6, 7, and 8. It is supported from version 4 in chrome and 2 in firefox.
59. How many parameters does the method plot() accept?
A. 7
B. 8
C. 9
D. 10
View Answer
Ans : C
Explanation: Plot() is a generic function, meaning, it has many methods which are called according to the type of object passed to plot() . The method plot() accepts a total of 9 parameters.
60.What is the purpose of script loading?
A. Load Scripts programmatically
B. Load JavaScript files manually
C. Load JavaScript files programmatically
D. All of the mentioned
View Answer
Ans : C
Explanation:The script loading loads remote JavaScript files programmatically and allow us to trick the rendering engine. The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available.
61.JavaScript can be written __________
A. directly into JS file and included into HTML
B. directly on the server page
C. directly into HTML pages
D. directly into the css file
View Answer
Ans : A
Explanation:Javascript files can be saved by .js extension and can be included in HTML files. Script tags are used with the src attribute to include Js files. explanation.
62. When a class B can extend another class A, we say that:
A. A is the superclass and B is the subclass
B. B is the superclass and A is the subclass
C. Both A and B are the superclass
D. Both A and B are the subclass
View Answer
Ans : A
Explanation:Superclass is the class from which subclasses are defined. Subclasses are also called the extension of the superclass. In the above scenario, there will be a superclass and B is collas.
63. Which method receives the return value of setInterval() to cancel future invocations?
A. clearInvocation()
B. cancelInvocation()
C. clearInterval()
D. clear()
View Answer
Ans : C
Explanation: Like setTimeout(), setInterval() returns a value that can be passed to clearInterval() to cancel any future invocations of the scheduled function. The ID value returned by setInterval() is used as the parameter for the clearInterval() method.
64. The pop() method of the array does which of the following task ?
A. decrements the total length by 1
B. increments the total length by 1
C. prints the first element but no effect on the length
D. updates the element
View Answer
Ans : A
Explanation: pop() function pops out that is delete the last element from the array. Hence pop() method (it works with push()) reduces the length of an array by 1.
65. What will be the return value of the write() method when the Node cannot write the data immediately and has to buffer it internally?
A. 0
B. 1
C. True
D. False
View Answer
Ans : D
Explanation:The write() method writes HTML expressions or JavaScript code to a document. The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML. write() method never blocks. If Node cannot write the data immediately and has to buffer it internally, the write() method returns false.
66. What will happen if you reference document.location from within an object?
A. Traverses the queue
B. Finds the bugs
C. Traverses the stack
D. Traverses the array
View Answer
Ans : C
Explanation:window.location.href returns the href (URL) of the current page. If you reference document.location from within an object, the interpreter will need to go from the function that references the variable, up out of the namespace to the global window scope, down to the document scope, and get the location value.
67. What is a closure?
A. Function objects
B. Scope where function’s variables are resolved
C. Both Function objects and Scope where function’s variables are resolved
D. Function return value
View Answer
Ans : C
Explanation: A combination of a function object and a scope (a set of variable bindings) in which the function’s variables are resolved is called a closure.
68. Which is the method invoked to connect the last vertex back to the first?
A. closePath()
B. close()
C. connectlast(first)
D. connect()
View Answer
Ans : A
Explanation: The closePath() method connects the last vertex back to the first, thereby creating a path. It connects the last point to the first point thereby creating a closed figure.
69. What is the need for bubble charts?
A. Represent 2D data
B. Represent 3D data
C. Represent 2D and 3D data
D. Represents meta data
View Answer
Ans : B
Explanation:A bubble plot is a scatterplot where a third dimension is added: the value of an additional variable is represented through the size of the dots. They are used to represent three-dimensional data.
70. How to get a particular value using the tagged name?
A. getElementbyID()
B. getElementsbyName()
C. getElementsbyTagName()
D. getTagName()
View Answer
Ans : C
Explanation:The getElementsByTagName() method returns a collection of all elements in the document with the specified tag name, as a NodeList object. The method getElementsbyTagName() can be used to get a particular value using the tagged name associated with the document.
71. Which of the following is the correct syntax to display "Letsfindcourse" in an alert box using JavaScript?
A. alert-box("Letsfindcourse");
B. confirm("Letsfindcourse");
C. msgbox("Letsfindcourse");
D. alert("Letsfindcourse");
View Answer
Ans : D
Explanation: To display any text in the alert box, you need to write it as alert("Letsfindcourse");
72. What is the correct syntax for referring to an external script called "LFC.js"?
A. <script src="LFC.js">
B. <script source="LFC.js">
C. <script ref="LFC.js">
D. <script type="LFC.js">
View Answer
Ans : A
Explanation:The "src" term is used to refer to any JavaScript file. JavaScript.
73. Which of the following is not Javascript frameworks or libraries?
A. Polymer
B. Meteor
C. Cassandra
D. jQuery
View Answer
Ans : C
Explanation: Cassandra is a distributed database from Apache.So the option C is not Javascript frameworks or libraries.
74. Why so JavaScript and Java have similar name?
A. JavaScript is a stripped-down version of Java
B. JavaScript's syntax is loosely based on Java's
C. They both originated on the island of Java
D. None of the above
View Answer
Ans : B
Explanation: Because JavaScript's syntax is loosely based on Java's that's why JavaScript and Java have similar name.
75. What is the original name of JavaScript?
A. LiveScript
B. EScript
C. Mocha
D. JavaScript
View Answer
Ans : C
Explanation:The project was originally called Mocha, then renamed to LiveScript, and finally to JavaScript when Netscape and Sun did a license agreement. The idea at the time was to make it a scripting language complimentary to Java.
Also check :
Discussion