WorksheetsJavascript Basic
Total questions: 20
Worksheet time: 10mins
What is a JavaScript variable?
A container that holds a value
A function that performs a task
A way to add styles to a website
A type of data
How do you write a JavaScript string?
"Hello World!"
Hello World!
'Hello World!'
`Hello World!`
What is the difference between = and == in JavaScript?
= assigns a value to a variable and == compares values
= compares values and == assigns a value to a variable
= and == are the same thing
= assigns a value to a variable and == assigns a value to a variable
How do you create a JavaScript function?
create function myFunction() {}
new function myFunction() {}
myFunction() {}
function myFunction() {}
How do you write a JavaScript alert?
alert = "Hello World!";
alert {Hello World!};
alert("Hello World!");
alert "Hello World!";
How do you write a JavaScript comment?
# This is a comment
// This is a comment
/* This is a comment */
-- This is a comment
How do you change the background color of an HTML element using JavaScript?
element.color = "red";
element.background = "red";
element.style.backgroundColor = "red";
element.setBackground("red");
What is JavaScript used for?
Creating interactive websites
Making video games
Designing graphics
All of the answers
How do you add an event listener to a button in JavaScript?
button.addEventListener("click", myFunction);
button.listenEvent("click", myFunction);
button.onEvent("click", myFunction);
button.eventListener("click", myFunction);
What is the result of the following code? var x = 5; x++;
4
5
6
7
What is the keyword used to create a loop in JavaScript?
loop
repeat
for
if
What is the result of the following code? var x = "5"; x = x + 2;
7
52
"52"
"7"
How do you print a message to the console in JavaScript?
print("Hello World!");
console.log("Hello World!");
document.write("Hello World!");
alert("Hello World!");
What is the symbol used to multiply two numbers in JavaScript?
x
/
-
*
What is the correct way to write an if-else statement in JavaScript?
if x = 5 { } else { }
if x == 5 { } else { }
if (x == 5) { } else { }
if x = 5 then { } else { }
What is the Document Object Model (DOM)?
A programming language
A way to interact with HTML documents
A database
A type of software
What is the purpose of the DOM?
To create interactive websites
To store data
To provide a way for programming languages to access and manipulate web pages
To enable web browsers to display images and text
How do you select an element using JavaScript?
document.getElementById()
document.getElementsByClassName()
document.getElementsByTagName()
All of the above
How do you change the text of an element using JavaScript?
element.changeText()
element.updateText()
element.innerHTML = "new text"
element.setText("new text")
Can you select multiple elements at once using the getElementById method in JavaScript?
Yes
No
