🧪 JavaScript MCQ Quiz Hub

JavaScript MCQ Set 1

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

1. What is JavaScript?




2. Which of the following is correct about JavaScript?




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




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;




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>




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




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




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;




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




10. Which of the following is not javascript data types?




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




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;




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




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




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




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




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




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




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




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




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




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




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




24. Which of the following scoping type does JavaScript use?




25. What is the basic difference between JavaScript and Java?




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




27. Why JavaScript Engine is needed?




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




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




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




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




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




33. Which of the following is not a framework?




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




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




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




37. Which of the following is not an error in JavaScript?




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;




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




40. The main purpose of a “Live Wire” in NetScape is to ________




41. The script tag must be placed in __________




42. A JavaScript program developed on a Unix Machine ________




43. JavaScript is ideal to ________




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




45. JavaScript Code can be called by using ____________




46. JavaScript can be written __________




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




48. A proper scripting language is a __________




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;




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>




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>




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>




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




54. JavaScript Code can be called by using ___________




55. The type of a variable that is volatile is _______________




56. A hexadecimal literal begins with __________




57. The generalised syntax for a real number representation is __________




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




59. The escape sequence ‘f’ stands for _________




60. The snippet that has to be used to check if “a” is not equal to “null” is _________




61. The statement a===b refers to _________




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




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




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




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




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




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




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




69. A function definition expression can be called as __________




70. The property of a primary expression is ____________




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 ____________




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




73. What kind of expression is “new Point(2,3)”?




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




75. Among the following, which one is a ternary operator?