wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Basic JavaScript

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the correct way to declare a variable in JavaScript?

a)

variable = 10;

b)

const variable = 10;

c)

variable := 10;

d)

variable == 10;

2.

What is the result of the following expression: 5 + "5";

a)

10

b)

"55"

c)

Nan

d)

Error

3.

Which function is used to display a message in the browser's console

a)

console.print()

b)

log()

c)

print()

d)

console.log()

4.

What is the correct way to create a function in JavaScript?

a)

function = myFunction() {}

b)

function myFunction() {}

c)

let myFunction() {}

d)

function myFunction: {}

5.

What is the output of the following code?

a)

10

b)

5

c)

undefined

d)

Error

6.

What is the correct way to create an array in JavaScript?

a)

array = [1, 2, 3];

b)

array(1, 2, 3);

c)

array = {1, 2, 3};

d)

array = (1, 2, 3)

7.

What is the result of the expression true && false

a)

true

b)

false

c)

undefined

d)

Error

8.

What is the correct way to create an object in JavaScript?

a)

object = {name: "John", age: 30}

b)

object(name = "John", age = 30)

c)

object = (name: "John", age: 30)

d)

object = [name: "John", age: 30]

9.

What does the === operator in JavaScript do?

a)

Checks for equality of values and data type

b)

Checks for equality of values and not data types

c)

Assigns a value to a variable

d)

Performs a bitwise OR operation

10.

What is the correct way to access the length of an array in JavaScript?

a)

array.length()

b)

length(array)

c)

array.length

d)

array.getLength()

11.

What is the correct way to access the value of a property in an object?

a)

object.propertyName

b)

object.getProperty("propertyName")

c)

object.getPropertyName()

d)

object(propertyName)

12.

What is the correct way to remove the last element from an array in JavaScript?

a)

array.removeLast()

b)

array.popLast()

c)

array.pop()

d)

array.deleteLast()

13.
var result = 10 + "20" - 5;
a)

result = "5025"

b)

result = "205"

c)

result = 1015

d)

Error

14.

Which method is used to convert a string to uppercase in JavaScript?

a)

toUpperCase

b)

toUpper

c)

upperCase

d)

convertToUpper

15.

What is the output of the code?

a)

Error

b)

10

c)

20

d)

undefined