JavaScript Quiz | Set-2

Prerequisite: Basic understanding of JavaScript concepts
1. 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();
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!=5
Explanation: JavaScript do not accept <> operator as not equal to.


4. What is the correct syntax for adding comments in JavaScript?
A) <!–This is a comment–&gt 
B) //This is a comment 
C) –This is a comment 
D) **This is a comment**
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–&gt 
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**
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”]
Explanation: In JavaScript, functions are called directly like x().


8. What will be the output of the following code?








A) float 
B) number 
C) integer 
D) double
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”));
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()
Explanation: The trim() method in JavaScript is used to remove the whitespaces at the beginning and end of the string. 




My Personal Notes arrow_drop_up

BTech Computer Science student at IIIT Vadodara

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : BhagyaRana

Article Tags :


Please write to us at to report any issue with the above content.