JavaScript Quiz | Set-2 - GeeksforGeeks

11 Oct, 2021
Prerequisite: Basic understanding of JavaScript concepts1. What is the syntax for creating a function in JavaScript named as Geekfunc? A) function = Geekfunc() B) function Geekfunc() C) function := Geekfunc() D) function : Geekfunc()Ans: Option B Explanation: In JavaScript, function is defined as ‘function x()’. 2. How is the function called in JavaScript?A) call Geekfunc(); B) call function GeekFunc(); C) Geekfunc(); D) function Geekfunc();Ans: C Explanation: In JavaScript, functions are called directly like x(). 
3. How to write an ‘if’ statement for executing some code. If “i” is NOT equal to 5?A) if(i<>5) B) if i<>5 C) if(i!=5) D) if i!=5Ans: C Explanation: JavaScript does not accept <> operator as not equal to. 
4. What is the correct syntax for adding comments in JavaScript?A) <!–This is a comment–> B) //This is a comment C) –This is a comment D) **This is a comment**Ans: B Explanation: Correct Syntax for comments in JavaScript is //comment.  5. How to insert a multi-line comment in JavaScript?A) <!–This is comment line 1 This is comment line 2–> B) //This is comment line 1 This is comment line 2// C) /*This is comment line 1 This is comment line 2*/ D) **This is comment line 1 This is comment line 2**Ans: C Explanation: Correct Syntax for multi-line comments in JavaScript is /*comment*/. 
6. What is the JavaScript syntax for printing values in Console?A) print(5) B) console.log(5); C) console.print(5); D) print.console(5);Ans: Option B Explanation: The action which is built into the console object is the .log() method. Whenever we write console.log() in the JavaScript code, what we put inside the parentheses will get printed, or logged, to the console. 
7. How to initialize an array in JavaScript?A) var Geeks= “Geek1”, “Geek2”, “Geek3” B) var Geeks=(1:Geek1, 2:Geek2, 3:Geek3) C) var Geeks=(1=Geek1, 2=Geek2, 3=Geek3) D) var Geeks=[“Geek1”, “Geek2”, “Geek3”]Ans: D Explanation: In JavaScript, functions are called directly like x(). 8. What will be the output of the following code?
javascript
<script>document.write(typeof(24.49));</script>
A) float B) number C) integer D) doubleAns: B Explanation: There are seven fundamental data types in JavaScript. They are number, string, boolean, null, undefined, symbol, and object. We do not have data types like float, integer, and double in JavaScript.  9. What will be the command to print the number of characters in the string “GeeksforGeeks”? A) document.write(“GeeksforGeeks”.len); B) document.write(sizeof(“GeeksforGeeks”)); C) document.write(“GeeksforGeeks”.length); D) document.write(lenof(“GeeksforGeeks”));Ans: C Explanation: The .length property of JavaScript is used to evaluate the number of characters in any string. 10. What is the method in JavaScript used to remove the whitespace at the beginning and end of any string?A) strip() B) trim() C) stripped() D) trimmed()Ans: B Explanation: The trim() method in JavaScript is used to remove the whitespaces at the beginning and end of the string.  11. Which of the following is the pop() method does?
A) Display the first element B) Decrements length by 1C) Increments length by 1D) None of the mentioned
Answer: Option BExplanation: The pop() method in JavaScript is used the remove the last element of the array. Hence the answer is option B.
12.Which of the following option is correct if reverse() and join() are used together?
A) Reverses and stores B) Reverses and concatenates  C) Only ReversesD) None of the mentioned
Answer: Option AExplanation: The reverse() and join() method in javascript is used to reverse the arrays and later on the store the result.
13. Which of the following option is correct when a function with no return type is called?
A) Dynamic functionB) ProceduresC) Static functionD) Method
Answer: Option BExplanation: The correct definition of the procedure is the function with no return type Hence the correct option is Procedures.
14 . Which of the following scope is used by the JavaScript?
A) SegmentalB) LexicalC) LiteralD) Sequential
Answer: LexicalExplanation: In the lexical scope the function are executed between the given variable scope
15.Which of the following in reduce operation called?
A) filter and foldB) inject and foldC) finger and foldD) fold 
Answer: Option BExplanation: The reduced operation in javaScript is the callback function that is injected and fold, Hence the option is to inject and bold.
BhagyaRana
nishantsinghgfg
anikakapoor
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