JavaScript Fundamentals
Test your knowledge of JavaScript basics including variables, operators, loops, functions, arrays, comments, and browser interaction.
Questions
Is JavaScript case-sensitive?
- No
- Yes
What will the following code return: Boolean(10 > 9)?
- NaN
- false
- true
Which operator is used to assign a value to a variable?
- *
- =
- -
- x
How do you declare a JavaScript variable?
- variable carName;
- v carName;
- var carName;
Which event occurs when the user clicks on an HTML element?
- onchange
- onclick
- onmouseclick
- onmouseover
How can you detect the client's browser name?
- browser.name
- navigator.appName
- client.navName
JavaScript is the same as Java.
- True
- False
What is the correct JavaScript syntax for opening a new window called "w2" ?
- w2 = window.new("http://www.site.com");
- w2 = window.open"http://site.com");
How do you find the number with the highest value of x and y?
- Math.ceil(x, y)
- Math.max(x, y)
- top(x, y)
- ceil(x, y)
How do you round the number 7.25, to the nearest integer?
- Math.round(7.25)
- rnd(7.25)
- Math.rnd(7.25)
- round(7.25)
What is the correct way to write a JavaScript array?
- var colors = "red", "green", "blue"
- var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")
- var colors = (1:"red", 2:"green", 3:"blue")
- var colors = ["red", "green", "blue"]
How to insert a comment that has more than one line?
- <!--This comment hasmore than one line-->
- //This comment has more than one line//
- /This comment hasmore than one line/
How can you add a comment in a JavaScript?
- //This is a comment
- <!--This is a comment-->
- 'This is a comment
How does a FOR loop start?
- for (i = 0; i <= 5)
- for i = 1 to 5
- for (i <= 5; i++)
- for (i = 0; i <= 5; i++)
How does a WHILE loop start?
- while (i <= 10)
- while (i <= 10; i++)
- while i = 1 to 10
How to write an IF statement for executing some code if "i" is NOT equal to 5?
- if (i != 5)
- if i <> 5
- if i =! 5 then
- if (i <> 5)
How to write an IF statement in JavaScript?
- if i = 5
- if i == 5 then
- if (i == 5)
- if i = 5 then
How do you call a function named "myFunction"?
- call function myFunction()
- myFunction()
- call myFunction()
How do you write "Hello World" in an alert box?
- alert("Hello World");
- msg("Hello World");
- alertBox("Hello World");
- msgBox("Hello World");
The external JavaScript file must contain the <script> tag.
- False
- true
Where is the correct place to insert a JavaScript?
- The <body> section
- The <head> section
- Both the <head> section and the <body> section are correct
Inside which HTML element do we put the JavaScript?
- <scripting>
- <script>
- <javascript>
- <js>