Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Quiz | Set-2

  • Difficulty Level : Basic
  • Last Updated : 11 Oct, 2021

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();
Ans:
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
Ans:
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:
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:
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:
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) double
Ans:
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:
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:
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 1
C) Increments length by 1
D) None of the mentioned

Answer: Option B
Explanation: 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 Reverses
D) None of the mentioned

Answer: Option A
Explanation: 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 function
B) Procedures
C) Static function
D) Method

Answer: Option B
Explanation: 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) Segmental
B) Lexical
C) Literal
D) Sequential

Answer: Lexical
Explanation: 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 fold
B) inject and fold
C) finger and fold
D) fold 

Answer: Option B
Explanation: The reduced operation in javaScript is the callback function that is injected and fold, Hence the option is to inject and bold.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!