WorksheetsJavaScript Fundamentals for Students
Total questions: 15
Worksheet time: 8mins
What is a variable in JavaScript?
A variable in JavaScript is a named container for storing data values.
A variable in JavaScript is a method for defining classes.
A variable in JavaScript is a function that performs calculations.
A variable in JavaScript is a type of loop used for iteration.
Which of the following is a valid way to declare a variable?
let x = 5;
x = 5;
const x : 5;
var x = 5;
What are the different data types in JavaScript?
string, number, boolean, null, undefined, symbol, object
array, function, set
date, time, list
integer, float, character
How do you convert a string to a number in JavaScript?
Apply Math.round(string)
Convert using toString(string)
Use stringToNumber(string) method
Use Number(string), parseInt(string), or parseFloat(string) to convert a string to a number.
What is the purpose of a function in JavaScript?
To store data in variables
The purpose of a function in JavaScript is to encapsulate code for reuse and to perform specific tasks.
To define global variables
To create HTML elements
What is the difference between function declaration and function expression?
Function expression can be called before its definition.
Function declaration can only be used in strict mode.
Function declaration is hoisted and can be called before its definition, while function expression is not hoisted and must be defined before it can be called.
Function declaration and function expression are the same.
What is scope in JavaScript?
Scope is the method of error handling in JavaScript.
Scope is a type of JavaScript function.
Scope refers to the speed of JavaScript execution.
Scope in JavaScript defines the visibility and lifetime of variables and functions.
How can you access a variable defined in an outer function from an inner function?
You must declare the outer variable as global to access it in the inner function.
You can reference the outer variable directly by its name in the inner function.
You can only access the outer variable by passing it as an argument.
Inner functions cannot access outer variables at all.
What does DOM stand for in web development?
Data Object Model
Document Object Module
Dynamic Object Model
Document Object Model
How do you select an element by its ID in JavaScript?
document.getElementById('yourElementId');
getElementById('yourElementId');
document.selectById('yourElementId');
document.getElement('yourElementId');
What method would you use to change the text content of an HTML element?
Use the 'textContent' property in JavaScript.
Use the 'innerHTML' property in JavaScript.
Change the CSS style of the element.
Use the 'setAttribute' method to modify the element.
How can you add a new element to the DOM?
Call the appendChild method on the document to add an element.
Use document.getElementById('elementId') to create a new element.
Modify the innerHTML property of an existing element to add a new element.
Use document.createElement('elementType') and append it to the DOM.
What is event handling in JavaScript?
Event handling is a method for creating animations in JavaScript.
Event handling refers to the process of defining variables in JavaScript.
Event handling is the way to manage memory allocation in JavaScript.
Event handling in JavaScript is the mechanism that allows developers to execute code in response to user actions or events.
How do you remove an element from the DOM?
Use element.remove() or parentNode.removeChild(element).
Call removeElement(element) method.
Use element.delete() to remove an element.
Set element.style.display to 'none' to hide it.
What is the purpose of the 'this' keyword in JavaScript?
The 'this' keyword is used to create new objects.
The 'this' keyword is used to refer to the current execution context or object.
The 'this' keyword is used to declare global variables.
The 'this' keyword is a way to define functions in JavaScript.
