Olete.in
Articles
Mock Tests
🧪 JavaScript MCQ Quiz Hub
JavaScript MCQ Set 1
Choose a topic to test your knowledge and improve your JavaScript skills
1. What is JavaScript?
JavaScript is a scripting language used to make the website interactive b) e
JavaScript is an assembly language used to make the website interactiv
JavaScript is a compiled language used to make the website interactive
None of the mentioned
2. Which of the following is correct about JavaScript?
JavaScript is an Object-Based language
JavaScript is Assembly-language
JavaScript is an Object-Oriented language
JavaScript is a High-level language
3. Among the given statements, which statement defines closures in JavaScript?
JavaScript is a function that is enclosed with references to its inner function scope
JavaScript is a function that is enclosed with references to its lexical environment
JavaScript is a function that is enclosed with the object to its inner function scope
None of the mentioned
4. What will be the output of the following JavaScript code snippet? <p id="demo"></p> var txt1 = "Sanfoundry_"; var txt2 = "Javascriptmcq"; document.getElementById("demo").innerHTML = txt1 + txt2;
error
Sanfoundry_ Javascriptmcq
undefined
Sanfoundry_Javascriptmcq
5. What will be the output of the following JavaScript code? <p id="demo"></p> <script> var js = 10; js *= 5; document.getElementById("demo").innerHTML = js; </script>
10
50
5
Error
6. Arrays in JavaScript are defined by which of the following statements?
It is an ordered list of values
It is an ordered list of objects
It is an ordered list of string
It is an ordered list of functions
7. What will be the output of the following JavaScript code? // JavaScript Comparison Operators function compare() { int num=2; char b=2; if(a==b) return true; else return false; }
false
true
compilation error
runtime error
8. What will be the output of the following JavaScript code snippet? // JavaScript Equalto Operators function equalto() { int num=10; if(num===”10”) return true; else return false;
false
true
compilation error
runtime error
9. Will the following JavaScript code work? var js = (function(x) {return x*x;}(10));
Exception will be thrown
Memory leak
Error
Yes, perfectly
10. Which of the following is not javascript data types?
Null type
Undefined type
Number type
All of the mentioned
11. Where is Client-side JavaScript code is embedded within HTML documents?
A URL that uses the special javascript:code
A URL that uses the special javascript:protocol
A URL that uses the special javascript:encoding
A URL that uses the special javascript:stack
12. What will be the output of the following JavaScript code snippet? int a=1; if(a!=null) // JavaScript not equal to Operators return 1; else return 0;
0
1
compiler error
runtime error
13. Which of the following object is the main entry point to all client-side JavaScript features and APIs?
Position
Standard
Location
Window
14. What will be the output of the following JavaScript program? function sanfoundry(javascript) { return (javascript ? “yes” : “no”); } bool ans=true; console.log(sanfoundry(ans));
Compilation error
Runtime error
Yes
No
15. What will be the output of the following JavaScript code? // Javascript code snippet to compare the height function height() { var height = 123.56; var type = (height>=190) ? "tall" : "short"; return type; }
short
123.56
tall
190
16. Which of the following can be used to call a JavaScript Code Snippet?
Function/Method
Preprocessor
Triggering Event
RM1
17. What will be the output of the following JavaScript function? <p id="demo"></p> <script> function javascript() { // javacript abs() method document.getElementById("demo").innerHTML = Math.abs(-7.25);
-7.25
7.25
-7
7
18. What will be the output of the following JavaScript code? var a=5 , b=1 var obj = { a : 10 } // with keyword in JavaScript with(obj) { alert(b) }
1
10
5
Error
19. Which is a more efficient JavaScript code snippet? Code 1 : // for loop in javascript for(var num=10;num>=1;num--) { document.writeln(num); } Code 2 : var num=10; while(num>=1) { document.writeln(num); num++; }
Code 1
Code 2
Both Code 1 and Code 2
Cannot Compare
20. Which of the following explains correctly what happens when a JavaScript program is developed on a Unix Machine?
will work perfectly well on a Windows Machine
will be displayed as JavaScript text on the browser
will throw errors and exceptions
must be restricted to a Unix Machine only
21. What will be the output of the following JavaScript code? function printArray(a) { var len = a.length, i = 0; if (len == 0) console.log("Empty Array"); else { // do-while loop in javascript do { console.log(a[i]); } while (++i < len); } }
Prints “Empty Array”
Prints 0 to the length of the array
Prints the numbers in the array in order
Prints the numbers in the array in the reverse order
22. What happens in the following JavaScript code snippet? var js = 0; while (js < 10) { console.log(js); js++; }
An exception is thrown
The values of js are logged or stored in a particular location or storage c)
The value of js from 0 to 9 is displayed in the console
An error is displayed
23. What will be the output of the following JavaScript code? function range(int javascript) { int a=5; for(int i=0;i<javascript;i++) { console.log(a); } } range(3);
2
5
55
Error
24. Which of the following scoping type does JavaScript use?
Sequential
Segmental
Lexical
Literal
25. What is the basic difference between JavaScript and Java?
Functions are considered as fields
Functions are values, and there is no hard distinction between methods and fields
Variables are specific
There is no difference
26. What will be the output of the following JavaScript code? var quiz=[1,2,3]; var js=[6,7,8]; var result=quiz.concat(js); document.writeln(result);
1, 2, 3, 6, 7, 8
123
1, 2, 3
Error
27. Why JavaScript Engine is needed?
Both Compiling &amp; Interpreting the JavaScript
Parsing the javascript
Interpreting the JavaScript
Compiling the JavaScript
28. What will be the function of the following JavaScript program? var scope = "js scope"; function checkscope() { var scope = "javascript scope"; function f() { return scope; } return f; }
Returns the value in scope
Returns value null
Shows an error message
Returns exception
29. What will be the output of the following JavaScript code? int a=0; for(a;a<5;a++); console.log(a);
4
5
0
Error
30. Which of the following methods/operation does javascript use instead of == and !=?
JavaScript uses equalto() b) d)
JavaScript uses equals() and notequals() instead
JavaScript uses bitwise checking
JavaScript uses === and !== instead
31. What will be the result or type of error if p is not defined in the following JavaScript code snippet? console.log(p)
Value not found Error
Reference Error
Null
Zero
32. What is the prototype represents in the following JavaScript code snippet? function javascript() {};
Not valid
Prototype of a function
Function javascript d)
A custom constructor
33. Which of the following is not a framework?
JavaScript .NET
JavaScript
Cocoa JS
jQuery
34. Which of the following is the property that is triggered in response to JS errors?
onclick
onerror
onmessage
onexception
35. What will be the output of the following JavaScript code? function compare() { int sanfoundry=1; char javascript=1; if(sanfoundry.tostring()===javascript) return true; else return false; }
runtime error
logical error
true
false
36. What will be the firstname and surname of the following JavaScript program? var book = { "main title": "JavaScript", 'sub-title': "The Definitive Guide", "for": "all audiences", author: { firstname: "David", surname: "Flanagan" } };
objects
property names
properties
property values
37. Which of the following is not an error in JavaScript?
Missing of Bracket
Division by zero
Syntax error
Missing of semicolons
38. Consider the following JavaScript statement containing regular expressions and check if the pattern matches. var text = "testing: 1, 2, 3"; var pattern = /d+/g;
text.check(pattern)
pattern.test(text)
text==pattern
text.equals(pattern)
39. The web development environment (JavaScript) offers which standard construct for data validation of the input entered by the user.
Controlled loop constructs
Server page access
Client side Event
Permit server-side
40. The main purpose of a “Live Wire” in NetScape is to ________
Create linkage between client side and server side
Permit server side, JavaScript code, to connect to RDBMS
Support only non relational database
To interpret JavaScript code
41. The script tag must be placed in __________
the head tag
the head or body
the title or head
after the body tag
42. A JavaScript program developed on a Unix Machine ________
will throw errors and exceptions
must be restricted to a Unix Machine only
will work perfectly well on a Windows Machine
will be displayed as a JavaScript text on the browser
43. JavaScript is ideal to ________
make computations in HTML simpler
minimize storage requirements on the web server
increase the download time for the client
increase the loading time of the website
44. Which attribute is used to specify that the script is executed when the page has finished parsing? (only for external scripts)
parse
a sync
defer
type
45. JavaScript Code can be called by using ____________
RMI
Triggering Event
Preprocessor
Function/Method
46. JavaScript can be written __________
directly into JS file and included into HTML
directly on the server page
directly into HTML pages
directly into the css file
47. Which of the following Attribute is used to include External JS code inside your HTML Document?
src
ext
script
link
48. A proper scripting language is a __________
High level programming language
Assembly level programming language
Machine level programming language
Low level programming language
49. What will be the output of the following JavaScript code? <p id="demo"></p> var txt1 = "good"; var txt2 = "day"; document.getElementById("demo").innerHTML = txt1 + txt2;
good day
goodday
error
undefined
50. What will be the output of the following JavaScript code? <p id="demo"></p> <script> var x = 5; var y = 2; var z = x % y; document.getElementById("demo").innerHTML = z; </script>
0
1
2
5
51. What will be the output of the following JavaScript code? <p id="demo"></p> <script> var x = 10; x *= 5; document.getElementById("demo").innerHTML = x; </script>
5
10
50
Error
52. What will be the output of the following JavaScript code? <p id="demo"></p> <script> txt1 = “ one”; txt1 += “two”; document.getElementById("demo").innerHTML = txt1; </script>
onetwo
one two
error
undefined
53. What will be the output of the following JavaScript code? <p id="demo"></p> <script> document.getElementById("demo").innerHTML = typeof "John" </script>
integer
number
string
error
54. JavaScript Code can be called by using ___________
RMI
Triggering Event
Preprocessor
Function/Method
55. The type of a variable that is volatile is _______________
Volatile variable
Mutable variable
Immutable variable
Dynamic variable
56. A hexadecimal literal begins with __________
00
0x
0X
Both 0x and 0X
57. The generalised syntax for a real number representation is __________
[digits][.digits][(E|e)[(+|-)]digits]
[digits][+digits][(E|e)[(+|-)]digits]
[digits][(E|e)[(+|-)]digits]
[.digits][digits][(E|e)[(+|-)]digits]
58. JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.
Prints an exception error
Prints an overflow error
Displays “Infinity”
Prints the value as such
59. The escape sequence ‘f’ stands for _________
Floating numbers
Representation of functions that returns a value
f is not present in JavaScript
Form feed
60. The snippet that has to be used to check if “a” is not equal to “null” is _________
if(a!=null)
if (!a)
if(a!null)
if(a!==null)
61. The statement a===b refers to _________
Both a and b are equal in value, type and reference address
Both a and b are equal in value
Both a and b are equal in value and type
There is no such statement
62. Assume that we have to convert “false” that is a non-string to string. The command that we use is (without invoking the “new” operator).
false.toString()
String(false)
String newvariable=”false”
Both false.toString() and String(false)
63. What will be the output of the following JavaScript code? function compare() { int num=2; char b=2; if(a==b) return true; else return false; }
true
false
runtime error
compilation error
64. What will be the output of the following JavaScript code? function equalto() { int num=10; if(num===”10”) return true; else return false; }
true
false
runtime error
compilation error
65. What will be the output of the following JavaScript code? function compare() { int a=1; char b=1; if(a.tostring()===b) return true; else return false; }
true
false
runtime error
logical error
66. What will be the output of the following JavaScript code? int a==2; int b=4; int ans=a+b; print(ans);
2
6
0
Error
67. . What will be the output of the following JavaScript code? int a=1; if(a!=null) return 1; else return 0;
0
1
runtime error
compiler error
68. What will be the output of the following JavaScript code? var string1 = ”123”; var intvalue = 123; alert( string1 + intvalue );
123246
246
123123
Exception
69. A function definition expression can be called as __________
Function prototype
Function literal
Function calling
Function declaration
70. The property of a primary expression is ____________
stand-alone expressions
basic expressions containing all necessary functions
contains variable references alone
contains only keywords
71. Consider the following JavaScript statements. var text = "testing: 1, 2, 3"; // Sample text var pattern = /d+/g // Matches all instances of one or more digits In order to check if the pattern matches with the string “text”, the statement is ____________
text==pattern
text.equals(pattern)
text.test(pattern)
pattern.test(text)
72. The expression of calling (or executing) a function or method in JavaScript is called ________
Primary expression
Functional expression
Invocation expression
Property Access Expression
73. What kind of expression is “new Point(2,3)”?
Primary Expression
Object Creation Expression
Invocation Expression
Constructor Calling Expression
74. Which of the operator is used to test if a particular property exists or not?
in
exist
within
exists
75. Among the following, which one is a ternary operator?
+
:
–
?:
Submit