JavaScript Quiz | Set-3

Prerequisite: Basic understanding of JavaScript concepts

1. In JavaScript, we do not have datatypes like integer and float. What is the function that can be used to check if the number is an integer or not?

A) Integer(value)
B) ifInteger(value)
C) isInteger(value)
D) ifinteger(value)



Ans: Option C
Explanation: isInteger() function is used to check whether a number is integer or not. The function is used as: document.write(number.isInteger(2018)) will result as true.

\linebreak

2. Predict the output on the console for the following JavaScript code.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
let myName = "Geek";
let myCity = "Geekistan";
  
console.log(`My name is ${myName}. My favorite city is ${myCity}.`)
</script>

chevron_right


A) Compilation Error
B) My name is Geek. My favorite city is Geekistan.
C) My name is ${myName}.My favorite city is ${myCity}.
D) 0

Ans: B
Explanation: In String Interpolation, ${variable} is used to refer to a variable’s value.
\linebreak

3. Predict the output on the console for the following JavaScript code.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
let geek = 'GeeksforGeeks';
  
console.log(typeof geek);
  
geek=1;
  
console.log(typeof geek);
</script>

chevron_right


A) string
number
B) string
string
C) null
null
D) string
integer

Ans: A
Explanation: typeof command will return the datatype of the variable.
\linebreak

4. Which of the following is an advantage of using JavaScript?

A) Increased interactivity.
B) Less server interaction.
C) Immediate feedback from the users.
D) All of the above.


Ans: D
Explanation: JavaScript ensures increased interactivity, less server interation and immediate feedback from the users.

\linebreak

5. Which function of an Array object calls a function for each element in the array?

A) forEach()
B) every()
C) forEvery()
D) each()

Ans: A
Explanation: forEach() – Calls a function for each element in the array.

\linebreak

6. JavaScript is a ________ Side Scripting Language.

A) Server
B) ISP
C) Browser
D) None of the above

Ans: Option C
Explanation: JavaScript is a Browser Side Scripting Language. ASP, PHP, Perl are Server Side Scripting Language.

\linebreak


7. Predict the output on the console for the following JavaScript code.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
      
    function geek() {
    if(true) {
        var a = 5;
    }
    document.write(a);
}
geek();                    
  
</script>

chevron_right


A) Compilation Error
B) Nothing will be printed as output
C) 5
D) Runtime error

Ans: C
Explanation: In JavaScript, the scope of variables is not changed in conditional statements and loops. Scope is only changed in case of functions, therefore a is defined even outside the ‘if’ conditional block.
\linebreak

8. JavaScript is ________ language.

A) a compiled
B) an interpreted

Ans: B
Explanation: JavaScript is an interpreted language, not a compiled language. C++ or Java codes needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. There is no such need in case of JavaScript.
\linebreak

9. Predict the output of the following JavaScript Code.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script type="text/javascript">
<!--
document.write("Hello");
//-->
</script>

chevron_right


A) Nothing
B) Compilation Error
C) Hello
D) <!–document.write(“Hello”);//–>

Ans: C
Explanation: To comment multiple lines in JavaScript, the syntax is /*comment*/.

\linebreak

10. Which was the first browser to support JavaScript?

A) Mozilla Firefox
B) Netscape
C) Google Chrome
D) IE

Ans: B
Explanation: Netscape was the first web browser to support JavaScript.
\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 :

1


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