Font size
WorksheetsMastering JavaScript Basics
Total questions: 16
Worksheet time: 11mins
What method would you use to create a new array with elements that pass a test?
Use the 'map' method.
Use the 'filter' method.
Use the 'forEach' method.
Use the 'reduce' method.
How do you combine all elements of an array into a single value?
Use array.concat() to merge arrays.
Use array.reduce() in JavaScript or a similar folding function in other languages.
Utilize array.filter() to select specific items.
Apply array.map() to transform elements.
What is the purpose of the rest parameter in a function?
The rest parameter is used to define default values for function parameters.
The purpose of the rest parameter is to collect all remaining arguments into an array.
The rest parameter limits the number of arguments a function can accept.
The rest parameter is a way to create named parameters in a function.
How does the spread operator work in JavaScript?
The spread operator combines multiple objects into one.
The spread operator is used to create a new array from an existing one.
The spread operator in JavaScript expands elements of an iterable into individual elements.
The spread operator is a method for defining functions in JavaScript.
What is variable scope and why is it important?
Variable scope is the method of defining variable types in a programming language.
Variable scope refers to the physical location of a variable in memory.
Variable scope is the context in which a variable is accessible in a program, and it is important for managing variable visibility, memory usage, and preventing conflicts.
Variable scope is the process of encrypting variable data for security.
How do you declare a 2D array in JavaScript?
let array2D = [1, 2, 3, 4];
let array2D = {1: [2, 3], 4: [5, 6]};
let array2D = new Array(2, 2);
let array2D = [[1, 2], [3, 4]];
Which method would you use to find the length of a string?
Use the 'length' property or function.
Use the 'size' method.
Count the number of characters manually.
Apply the 'getLength()' function.
What is the syntax for a switch statement?
switch(expression) { case value1: // code block; default: // code block; }
switch(expression) { case value1: // code block; break; case value2: // code block; break; default: // code block; }
switch(value1) { case expression: // code block; }
switch { case value1: // code block; break; }
What does the checked property do in a checkbox input?
The checked property determines the label text of the checkbox.
The checked property changes the color of the checkbox.
The checked property sets the size of the checkbox.
The checked property determines if a checkbox is selected or not.
How do you write an if statement to check if a number is positive?
if (number > 0) { /* code to execute if number is positive */ }
if (number == 0) { /* code to execute if number is zero */ }
if (number >= 0) { /* code to execute if number is non-negative */ }
if (number < 0) { /* code to execute if number is negative */ }
What is type conversion and why is it used?
Type conversion is the act of creating new data types from existing ones.
Type conversion is the process of combining two data types into one.
Type conversion is the process of changing a value from one data type to another, used to ensure compatibility and correctness in operations.
Type conversion is a method to delete unnecessary data types.
How can you get user input in JavaScript?
Use the `alert()` function to display messages.
Use the `prompt()` function or HTML input elements.
Use the `fetch()` function to retrieve user data.
Get input through console logs.
What are the arithmetic operators available in JavaScript?
&
+, -, *, /, %, ++, --
|
^
How do you declare a variable in JavaScript?
You declare a variable using 'declare'.
You declare a variable with 'set'.
You declare a variable using 'define'.
You declare a variable using 'var', 'let', or 'const'.
What is a callback function and how is it used?
A callback function is a function that cannot be executed until the program ends.
A callback function is a type of variable used to store data.
A callback function is a function passed to another function to be executed later, often used for handling asynchronous operations.
A callback function is a built-in function that automatically runs at the start of a program.
Write a function sumArray(arr) that takes an array of numbers and returns the sum of all the numbers using the reduce method.
