JavaScript Quiz | Set-3 - GeeksforGeeks

06 Dec, 2021
Prerequisite: Basic understanding of JavaScript concepts1. In JavaScript, we do not have data types like integer and float. What is the function that can be used to check if the number is an integer or not?A) Integer(value) B) ifInteger(value) C) isInteger(value) D) ifinteger(value)Ans: Option C Explanation: isInteger() function is used to check whether a number is integer or not. The function is used as: document.write(number.isInteger(2018)) will result as true.2. Predict the output on the console for the following JavaScript code.
javascript
<script>  let myName = "Geek";  let myCity = "Geekistan";   console.log(`My name is ${myName}. My favorite city is ${myCity}.`)</script>
A) Compilation Error B) My name is Geek. My favorite city is Geekistan. C) My name is ${myName}.My favorite city is ${myCity}. D) 0Ans: B Explanation: In String Interpolation, ${variable} is used to refer to a variable’s value. 3. Predict the output on the console for the following JavaScript code.
javascript
<script>let geek = 'GeeksforGeeks';console.log(typeof geek);geek=1;console.log(typeof geek);</script>
A) string number B) string string C) null null D) string integerAns: A Explanation: type of command will return the data type of the variable. 4. Which of the following is an advantage of using JavaScript?A) Increased interactivity. B) Less server interaction. C) Immediate feedback from the users. D) All of the above.Ans: D Explanation: JavaScript ensures increased interactivity, less server interaction and immediate feedback from the users.5. Which function of an Array object calls a function for each element in the array?A) forEach() B) every() C) forEvery() D) each()Ans: A Explanation: forEach() – Calls a function for each element in the array.6. JavaScript is a ________ Side Scripting Language. A) Server B) ISP C) Browser D) None of the aboveAns: Option C Explanation: JavaScript is a Browser Side Scripting Language. ASP, PHP, Perl are Server Side Scripting Language.7. Predict the output on the console for the following JavaScript code.
javascript
<script>         function geek() {    if(true) {        var a = 5;    }    document.write(a);}geek();                    </script>
A) Compilation Error B) Nothing will be printed as output C) 5 D) Runtime errorAns: C Explanation: In JavaScript, the scope of variables is not changed in conditional statements and loops. The scope is only changed in the case of functions, therefore a is defined even outside the ‘if’ conditional block. 8. JavaScript is ________ language.A) a compiled B) an interpretedAns: B Explanation: JavaScript is an interpreted language, not a compiled language. C++ or Java codes need to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. There is no such need in the case of JavaScript. 9. Predict the output of the following JavaScript Code.
javascript
<script type="text/javascript"><!--document.write("Hello");//--></script>
A) Nothing B) Compilation Error C) Hello D) <!–document.write(“Hello”);//–>Ans: C Explanation: To comment multiple lines in JavaScript, the syntax is /*comment*/. 10. Which was the first browser to support JavaScript?A) Mozilla Firefox B) Netscape C) Google Chrome D) IEAns: B Explanation: Netscape was the first web browser to support JavaScript. 11. In JavaScript which of the following is done when the interpreter encounters an empty statement?
A) Throws an errorB) Shows a warningC) Prompts to complete the statementD) Ignores the statements
Answer: Option DExplanation: In JavaScript when the interpreter encounters the empty statement then it  Ignores the statements.
12.What is the correct syntax for creating an object?
A) var book = Object();B) var book = new Object();C) var book = new Book();D) var book = new OBJECT();
Answer: Option BExplanation: The correct syntax for creating an object is var book = new Object(); .Hence option is B
13 . Which of the following is not the JavaScriopt operator?
A) typeofB) thisC) deleteD) new
Answer: Option BExplanation: This is a keyword so it is not an operator in javascript Hence option is B.
14 . Which of the following is the use of the <noscript > tag?
A) It prevents script for execution B) Displayed by non-JavaScript browsersC) It stops cookiesD) All of the above
Answer: Option BExplanation: The <noscript>tag is displayed by non-JavaScript browsers so the option is B.
15 . What happens when a document loads in javascript?
A) window.onload = displayTime;B)  onload = displayTime;C) window.onload = start;D) window. = displayTime;
Answer: Option AExplanation: when document loads in javascript then window.onload method is used to access the screen when a page is loading.
nishantsinghgfg
Sapna2001
JavaScript
Quizzes
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to append HTML code to a div using JavaScript ?
SDE SHEET - A Complete Guide for SDE Preparation
time.h localtime() function in C with Examples
Length of race track based on the final distance between participants
TCS DIGITAL PUZZLE | Lateral Thinking
Find index after traversing a permutation Array of 1 to N by K steps