Home

JavaScript Online Question

JavaScript is the same as Java. (A) True (B) False

How can you detect the client's browser name? (A) client.navName (B) navigator.appName (C) browser.name

Inside which HTML element do we put the JavaScript? (A) <js> (B) <scripting> (C) <script> (D) <javascript>

What is the correct JavaScript syntax to change the content of the HTML element below? <p id="demo">This is a demonstration.</p> (A) document.getElement("p").innerHTML = "Hello World!"; (B) document.getElementById("demo").innerHTML = "Hello World!"; (C) #demo.innerHTML = "Hello World!"; (D) document.getElementByName("p").innerHTML = "Hello World!";

Where is the correct place to insert a JavaScript? (A) Both the <head> section and the <body> section are correct (B) The <body> section (C) The <head> section

What is the correct syntax for referring to an external script called "xxx.js"? (A) <script name="xxx.js"> (B) <script src="xxx.js"> (C) <script href="xxx.js">

The external JavaScript file must contain the <script> tag. (A) True (B) False

How do you write "Hello World" in an alert box? (A) msgBox("Hello World"); (B) alertBox("Hello World"); (C) msg("Hello World"); (D) alert("Hello World");

How do you create a function in JavaScript? (A) function myFunction() (B) function:myFunction() (C) function = myFunction()

How do you call a function named "myFunction"? (A) call myFunction() (B) myFunction() (C) call function myFunction()

JavaScript Online Question

How to write an IF statement in JavaScript? (A) if i = 5 then (B) if i == 5 then (C) if (i == 5) (D) if i = 5

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 then (D) if (i <> 5)

How does a WHILE loop start? (A) while (i <= 10) (B) while (i <= 10; i++) (C) while i = 1 to 10

How does a FOR loop start? (A) for (i = 0; i <= 5) (B) for (i <= 5; i++) (C) for (i = 0; i <= 5; i++) (D) for i = 1 to 5

How can you add a comment in a JavaScript? (A) 'This is a comment (B) //This is a comment (C) <!--This is a comment-->

How to insert a comment that has more than one line? (A) /*This comment has more than one line*/ Correct answer (B) //This comment has more than one line// (C) <!--This comment has (D) more than one line-->

What is the correct way to write a JavaScript array? (A) var colors = (1:"red", 2:"green", 3:"blue") (B) var colors = ["red", "green", "blue"] (C) var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue") (D) var colors = "red", "green", "blue"

How do you round the number 7.25, to the nearest integer? (A) rnd(7.25) (B) Math.round(7.25) (C) Math.rnd(7.25) (D) round(7.25)

How do you find the number with the highest value of x and y? (A) ceil(x, y) (B) Math.max(x, y) (C) top(x, y) (D) Math.ceil(x, y)

What is the correct JavaScript syntax for opening a new window called "w2" ? (A) w2 = window.open("http://www.w3schools.com"); (B) w2 = window.new("http://www.w3schools.com");

JavaScript Online Question

Which event occurs when the user clicks on an HTML element? (A) onclick (B) onmouseover (C) onmouseclick (D) onchange

How do you declare a JavaScript variable? (A) v carName; (B) var carName; (C) variable carName;

Which operator is used to assign a value to a variable? (A) = (B) - (C) x (D) *

What will the following code return: Boolean(10 > 9) (A) true (B) false (C) NaN

Is JavaScript case-sensitive? (A) No (B) Yes