WorksheetsJS Snippet Quiz
Total questions: 8
Worksheet time: 4mins
What is JavaScript used for?
Styling web pages
Making web pages interactive
Creating web page layouts
Defining web page structure
How can you add JavaScript to an HTML file?
<script>
<js>
<javascript>
<code>
Which keyword is used to declare changing variables in JavaScript?
variable
int
var
char
What does the innerHTML property do in JavaScript?
Changes the content of an element
Changes the style of an element
Removes an element from the DOM
Adds a new element to the DOM
How do you select an element by its ID in JavaScript?
document.getElementByClassName()
document.getElementByName()
document.getElementById()
document.querySelector()
Which method is used to add an event listener in JavaScript?
addEventListener()
attachEvent()
onEvent()
addListenEvent()
What does event.preventDefault() do?
Stops the event from bubbling up the DOM tree
Prevents the default behavior of the event
Removes the event listener from the element
Stops the propagation of the event to other elements
What would be the output in this code segment?
const x = 5;
x = 4;
console.log(x);
error
const
4
5
