wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Intro to JS: Functions, Scope & Objects

Total questions: 8

Worksheet time: 9mins

Name
Class
Date
1.

What is the keyword used to define a function in JavaScript?

a)

define

b)

function

c)

method

d)

procedure

2.

In the context of JavaScript, what does the term "scope" refer to?

a)

The number of lines in a function

b)

The accessibility of variables and functions in different parts of the code

c)

The speed at which a function executes

d)

The size of the code block

3.

Given the function definition `function add(a, b) { return a + b; }`, what will `add(3, 4)` return?

a)

34

b)

7

c)

12

d)

undefined

4.

Consider the following code snippet: ```javascript var color = 'blue'; function changeColor() { var color = 'yellow'; console.log(color); } changeColor(); console.log(color); ``` What will be logged to the console?

a)

yellow, blue

b)

blue, yellow

c)

yellow, yellow

d)

blue, blue

5.

What will be the output of the following code? ```javascript var myDog = { name: 'Buddy', age: 5 }; delete myDog.age; console.log(myDog.age); ```

a)

5

b)

undefined

c)

null

d)

Error

6.

Analyze the following code and determine what it does: ```javascript function multiplyByTwo(n) { return n * 2; } var result = multiplyByTwo(4); console.log(result); ```

a)

It multiplies 4 by 2 and logs 8

b)

It adds 2 to 4 and logs 6

c)

It divides 4 by 2 and logs 2

d)

It logs an error

7.

Given the object `var car = { brand: 'Toyota', model: 'Corolla' };`, how can you check if the property `model` exists in the object?

a)

car.hasOwnProperty('model')

b)

'model' in car

c)

Both A and B

d)

Neither A nor B

8.

When defining a function, the definition must occur before it is called.

a)

true

b)

false