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.
2. Predict the output on the console for the following JavaScript code.
<script> let myName = "Geek" ; let myCity = "Geekistan" ; console.log(`My name is ${myName}. My favorite city is ${myCity}.`) </script> |
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.
3. Predict the output on the console for the following JavaScript code.
<script> let geek = 'GeeksforGeeks' ; console.log( typeof geek); geek=1; console.log( typeof geek); </script> |
A) string
number
B) string
string
C) null
null
D) string
integer
Ans: A
Explanation: typeof command will return the datatype of the variable.
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.
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.
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.
7. Predict the output on the console for the following JavaScript code.
<script> function geek() { if ( true ) { var a = 5; } document.write(a); } geek(); </script> |
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.
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.
9. Predict the output of the following JavaScript Code.
<script type= "text/javascript" > <!-- document.write( "Hello" ); //--> </script> |
A) Nothing
B) Compilation Error
C) Hello
D) <!–document.write(“Hello”);//–>
Ans: C
Explanation: To comment multiple lines in JavaScript, the syntax is /*comment*/.
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.