πŸ§ͺ JavaScript MCQ Quiz Hub

JavaScript MCQ Set 1

Choose a topic to test your knowledge and improve your JavaScript skills

What is JavaScript?





βœ… Correct Answer: 1

Which of the following is correct about JavaScript?





βœ… Correct Answer: 1

Among the given statements, which statement defines closures in JavaScript?





βœ… Correct Answer: 2

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;





βœ… Correct Answer: 4

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>





βœ… Correct Answer: 2

Arrays in JavaScript are defined by which of the following statements?





βœ… Correct Answer: 1

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; }





βœ… Correct Answer: 1

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;





βœ… Correct Answer: 2

Will the following JavaScript code work? var js = (function(x) {return x*x;}(10));





βœ… Correct Answer: 4

Which of the following is not javascript data types?





βœ… Correct Answer: 4

Where is Client-side JavaScript code is embedded within HTML documents?





βœ… Correct Answer: 2

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;





βœ… Correct Answer: 2

Which of the following object is the main entry point to all client-side JavaScript features and APIs?





βœ… Correct Answer: 1

What will be the output of the following JavaScript program? function sanfoundry(javascript) { return (javascript ? β€œyes” : β€œno”); } bool ans=true; console.log(sanfoundry(ans));





βœ… Correct Answer: 3

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; }





βœ… Correct Answer: 1

Which of the following can be used to call a JavaScript Code Snippet?





βœ… Correct Answer: 1

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);





βœ… Correct Answer: 2

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) }





βœ… Correct Answer: 3

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++; }





βœ… Correct Answer: 1

Which of the following explains correctly what happens when a JavaScript program is developed on a Unix Machine?





βœ… Correct Answer: 1

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); } }





βœ… Correct Answer: 3

What happens in the following JavaScript code snippet? var js = 0; while (js < 10) { console.log(js); js++; }





βœ… Correct Answer: 3

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);





βœ… Correct Answer: 3

Which of the following scoping type does JavaScript use?





βœ… Correct Answer: 3

What is the basic difference between JavaScript and Java?





βœ… Correct Answer: 2

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);





βœ… Correct Answer: 1

Why JavaScript Engine is needed?





βœ… Correct Answer: 3

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; }





βœ… Correct Answer: 1

What will be the output of the following JavaScript code? int a=0; for(a;a<5;a++); console.log(a);





βœ… Correct Answer: 2

Which of the following methods/operation does javascript use instead of == and !=?





βœ… Correct Answer: 4

What will be the result or type of error if p is not defined in the following JavaScript code snippet? console.log(p)





βœ… Correct Answer: 2

What is the prototype represents in the following JavaScript code snippet? function javascript() {};





βœ… Correct Answer: 4

Which of the following is not a framework?





βœ… Correct Answer: 2

Which of the following is the property that is triggered in response to JS errors?





βœ… Correct Answer: 2

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; }





βœ… Correct Answer: 3

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" } };





βœ… Correct Answer: 2

Which of the following is not an error in JavaScript?





βœ… Correct Answer: 2

Consider the following JavaScript statement containing regular expressions and check if the pattern matches. var text = "testing: 1, 2, 3"; var pattern = /d+/g;





βœ… Correct Answer: 2

The web development environment (JavaScript) offers which standard construct for data validation of the input entered by the user.





βœ… Correct Answer: 1

The main purpose of a β€œLive Wire” in NetScape is to ________





βœ… Correct Answer: 2

The script tag must be placed in __________





βœ… Correct Answer: 2

A JavaScript program developed on a Unix Machine ________





βœ… Correct Answer: 3

JavaScript is ideal to ________





βœ… Correct Answer: 2

Which attribute is used to specify that the script is executed when the page has finished parsing? (only for external scripts)





βœ… Correct Answer: 3

JavaScript Code can be called by using ____________





βœ… Correct Answer: 4

JavaScript can be written __________





βœ… Correct Answer: 1

Which of the following Attribute is used to include External JS code inside your HTML Document?





βœ… Correct Answer: 1

A proper scripting language is a __________





βœ… Correct Answer: 1

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;





βœ… Correct Answer: 2

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>





βœ… Correct Answer: 2

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>





βœ… Correct Answer: 3

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>





βœ… Correct Answer: 1

What will be the output of the following JavaScript code? <p id="demo"></p> <script> document.getElementById("demo").innerHTML = typeof "John" </script>





βœ… Correct Answer: 3

JavaScript Code can be called by using ___________





βœ… Correct Answer: 4

The type of a variable that is volatile is _______________





βœ… Correct Answer: 2

A hexadecimal literal begins with __________





βœ… Correct Answer: 4

The generalised syntax for a real number representation is __________





βœ… Correct Answer: 1

JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.





βœ… Correct Answer: 3

The escape sequence β€˜f’ stands for _________





βœ… Correct Answer: 4

The snippet that has to be used to check if β€œa” is not equal to β€œnull” is _________





βœ… Correct Answer: 4

The statement a===b refers to _________





βœ… Correct Answer: 3

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).





βœ… Correct Answer: 4

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; }





βœ… Correct Answer: 1

What will be the output of the following JavaScript code? function equalto() { int num=10; if(num===”10”) return true; else return false; }





βœ… Correct Answer: 1

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; }





βœ… Correct Answer: 1

What will be the output of the following JavaScript code? int a==2; int b=4; int ans=a+b; print(ans);





βœ… Correct Answer: 4

. What will be the output of the following JavaScript code? int a=1; if(a!=null) return 1; else return 0;





βœ… Correct Answer: 1

What will be the output of the following JavaScript code? var string1 = ”123”; var intvalue = 123; alert( string1 + intvalue );





βœ… Correct Answer: 3

A function definition expression can be called as __________





βœ… Correct Answer: 2

The property of a primary expression is ____________





βœ… Correct Answer: 1

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 ____________





βœ… Correct Answer: 4

The expression of calling (or executing) a function or method in JavaScript is called ________





βœ… Correct Answer: 3

What kind of expression is β€œnew Point(2,3)”?





βœ… Correct Answer: 2

Which of the operator is used to test if a particular property exists or not?





βœ… Correct Answer: 1

Among the following, which one is a ternary operator?





βœ… Correct Answer: 4