Saturday, November 23, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Quiz | Set-2

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, the 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–&gt 

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–&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**

Ans:

Explanation: Correct Syntax for multi-line comments in JavaScript is /*comment*/. 

6. What is the JavaScript syntax for printing values in the 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?

document.write(typeof(24.49));

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 “neveropen”? 

A) document.write(“neveropen”.len); 

B) document.write(sizeof(“neveropen”)); 

C) document.write(“neveropen”.length); 

D) document.write(lenof(“neveropen”));

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments