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()’.

\linebreak

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

\linebreak

3. How to write an ‘if’ statement for executing some code.
If “i” is NOT equal to 8?

A) if(i<>5)
B) if i<>5
C) if(i!=5)
D) if i!=5

Ans: C
Explanation: JavaScript do not accept <> operator as not equal to.

\linebreak

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: B
Explanation: Correct Syntax for comments in JavaScript is //comment.

\linebreak

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: C
Explanation: Correct Syntax for multi-line comments in JavaScript is /*comment*/.

\linebreak

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.

\linebreak

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

\linebreak

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
document.write(typeof(24.49));
</script>

chevron_right


A) float
B) number
C) integer
D) double

Ans: 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.
\linebreak

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.

\linebreak

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



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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.