Friday, December 27, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Quiz | Set-3

JavaScript Quiz | Set-3

Prerequisite: Basic understanding of JavaScript concepts

1. In JavaScript, we do not have data types like integers 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 an 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:

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 = 'neveropen';
    console.log(typeof geek);
    geek=1;
    console.log(typeof geek);
</script>

A) string 
     number 

B) string 
     string 

C) null 
     null 

D) string 
     integer

Ans:

Explanation: type of command will return the data type 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:

Explanation: JavaScript ensures increased interactivity, less server interaction 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:

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) {
        let a = 5;
    }
    document.write(a);
}
geek();                    

</script>

A) Compilation Error 

B) Nothing will be printed as output 

C)

D) Runtime error

Ans:

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

8. JavaScript is ________ language.

A) a compiled 

B) an interpreted

Ans:

Explanation: JavaScript is an interpreted language, not a compiled language. C++ or Java codes need 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 the 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:

Explanation: To comment on 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:

Explanation: Netscape was the first web browser to support JavaScript. 

11. In JavaScript which of the following is done when the interpreter encounters an empty statement?

A) Throws an error

B) Shows a warning

C) Prompts to complete the statement

D) Ignores the statements

Answer: Option D

Explanation: In JavaScript when the interpreter encounters an empty statement then it  Ignores the statement.

12. What is the correct syntax for creating an object?

A) var book = Object();

B) var book = new Object();

C) var book = new Book();

D) var book = new OBJECT();

Answer: Option B

Explanation: The correct syntax for creating an object is var book = new Object(); .Hence option is B

13 . Which of the following is not the JavaScriopt operator?

A) typeof

B) this

C) delete

D) new

Answer: Option B

Explanation: This is a keyword so it is not an operator in javascript Hence option is B.

14 . Which of the following is the use of the <noscript > tag?

A) It prevents the script for execution 

B) Displayed by non-JavaScript browsers

C) It stops cookies

D) All of the above

Answer: Option B

Explanation: The <noscript>tag is displayed by non-JavaScript browsers so the option is B.

15 . What happens when a document loads in javascript?

A) window.onload = displayTime;

B) onload = displayTime;

C) window.onload = start;

D) window. = displayTime;

Answer: Option A

Explanation: When the document loads in javascript then window.onload method is used to access the screen when a page is loading.

RELATED ARTICLES

Most Popular

Recent Comments