Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering JavaScript Concepts

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the purpose of the 'var' keyword in JavaScript?

a)

The 'var' keyword is used to define a function in JavaScript.

b)

The 'var' keyword is used to import modules in JavaScript.

c)

The 'var' keyword is used to declare a variable in JavaScript.

d)

The 'var' keyword is used to create a class in JavaScript.

2.

Explain the difference between 'let' and 'const'.

a)

'let' is block-scoped; 'const' is function-scoped.

b)

'let' cannot be redeclared; 'const' can be redeclared.

c)

'let' is used for constants; 'const' is for variables.

d)

'let' allows reassignment; 'const' does not.

3.

How do you select an element by its ID in the DOM?

a)

document.selectElementById('yourElementId')

b)

getElementById('yourElementId')

c)

document.getElementById('yourElementId')

d)

document.querySelector('#yourElementId')

4.

What method would you use to add a new class to an element?

a)

element.className.append('new-class');

b)

element.addClass('new-class');

c)

element.classList.add('new-class');

d)

element.classList.insert('new-class');

5.

How do you prevent the default action of an event?

a)

Return false in the event handler function.

b)

Use event.preventDefault() in the event handler.

c)

Use event.stopPropagation() in the event handler.

d)

Call event.cancelBubble() to stop the event.

6.

What is a function expression in JavaScript?

a)

A function expression is a type of variable declaration in JavaScript.

b)

A function expression is a built-in JavaScript method for creating objects.

c)

A function expression is a function defined within an expression, often assigned to a variable.

d)

A function expression is a function that cannot be assigned to a variable.

7.

How can you pass arguments to a function?

a)

By including them in the parentheses during function definition or call.

b)

By using global variables to store values.

c)

By passing them as return values from another function.

d)

By defining them as constants outside the function.

8.

What is the purpose of the 'try...catch' statement?

a)

To optimize code performance and speed up execution.

b)

To define variables and manage their scope effectively.

c)

To handle exceptions and prevent program crashes.

d)

To create loops and iterate over data structures.

9.

How do you throw a custom error in JavaScript?

a)

throw Error('Custom error');

b)

throw 'This is an error';

c)

throw new Exception('Error message');

d)

throw new Error('Your custom error message');

10.

What is the difference between synchronous and asynchronous functions?

a)

Synchronous functions block execution until complete, while asynchronous functions allow concurrent execution.

b)

Synchronous functions run in parallel, while asynchronous functions run sequentially.

c)

Asynchronous functions block execution until they are finished, unlike synchronous functions.

d)

Synchronous functions are faster than asynchronous functions in all cases.

11.

How can you create a new element in the DOM?

a)

Invoke document.newElement('tagName') to add an element to the DOM.

b)

Call document.insertElement('tagName') to create a new node.

c)

Use document.addElement('tagName') to insert a new element.

d)

Use document.createElement('tagName') to create a new element and append it to the DOM.

12.

What is the 'this' keyword in JavaScript?

a)

The 'this' keyword in JavaScript refers to the current execution context, which can vary based on how a function is called.

b)

The 'this' keyword is a reserved word that cannot be used in JavaScript.

c)

The 'this' keyword is used to define constants in JavaScript.

d)

The 'this' keyword always refers to the global object in JavaScript.

13.

How do you remove an event listener from an element?

a)

element.removeListener('eventType', functionReference);

b)

element.deleteEventListener('eventType', functionReference);

c)

element.removeEventListener('eventType', functionReference);

d)

element.detachEvent('eventType', functionReference);

14.

What is a callback function and how is it used?

a)

A callback function is a function passed to another function to be executed later, often used for handling asynchronous operations.

b)

A callback function is a method that runs in the background without user input.

c)

A callback function is a function that cannot be executed until the program ends.

d)

A callback function is a type of variable used to store data.

15.

What value is logged to the console?


javascript

let a = 10;

const b = 5;

console.log(a + "2" + b);

a)

17

b)

1025

c)

25

d)

107