Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

HTML_CSS_JS

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the issue in the following JavaScript code?

let obj = { a: 1, b: 2 };

console.log(obj.a + obj[c]);

a)

obj.c is not defined, leading to NaN

b)
  • c should be in quotes: obj["c"]

c)

c should be declared as a variable

d)

No issue

2.

Find the CSS syntax error:

.container {

width: 100px;

height: auto;

background-color: blue

}

a)

height: auto; is invalid

b)

Missing ; after background-color: blue

c)

width should be in rem

d)

No error

3.

Fix the bug in this JavaScript function:

function multiply(a, b) {

console.log(a * b);

}

let result = multiply(4, 5);

console.log(result);

a)

return a * b; inside the function

b)

Remove console.log(a * b);

c)

Call multiply as multiply(4)

d)

No fix needed

4.

What will be logged by the following code?

let a = 5;

let b = "5";

console.log(a == b, a === b);

a)

true false

b)

false true

c)

true true

d)

false false

5.

Find the bug in this CSS rule:

div {

display: flex;

justify-content: center space-between;

}

a)

justify-content cannot have both center and space-between

b)

display: flex; is not required

c)

center should be replaced with left

d)

No bug

6.

Fix the issue in this JavaScript snippet:

function test() {

let msg = "Hello";

}

console.log(msg);

a)

Move console.log(msg); inside the function

b)

Change let to var

c)

Define msg globally

d)

No fix needed

7.

Which of the following methods creates a shallow copy of an array

a)

slice()

b)

map()

c)

splice()

d)

forEach()

8.

Which CSS unit is NOT relative?

a)

em

b)

rem

c)

px

d)

vw

9.

What is the purpose of the defer attribute in <script> tag?

a)

Delays script execution until after the HTML is parsed

b)
  • Prevents script execution

c)

Makes script execution faster

d)

Runs the script immediately

10.

What is the purpose of event.stopPropagation() in JavaScript?

a)

Prevents event from bubbling up the DOM tree

b)
  • Prevents default action

c)

Stops JavaScript execution

d)

None of the above

11.

Which selector has the highest specificity?

a)

#id

b)

.class

c)

div

d)

*

12.
  1. Which CSS property controls an element’s visibility without removing it from the layout?

a)

display: none;

b)

visibility: hidden;

c)

opacity: 0;

d)

z-index: -1;

13.
  1. Complete the function to return unique elements of an array:

function unique(arr) {

return [...new ___(arr)];

}

a)

Set

b)

Map

c)

Array

d)

Object

14.

Which property ensures an element takes up the full width available?

width: __;

a)

auto

b)

100%

c)

fit-content

d)

max-content

15.

How to remove duplicates from an array?

let arr = [1, 2, 2, 3, 4, 4];

let uniqueArr = __;

a)

arr.filter()

b)

[...new Set(arr)]

c)

arr.splice()

d)

arr.sort()

16.

What will console.log(typeof NaN); print?

a)

number

b)

NaN

c)

undefined

d)

null

17.

Which CSS property is used to create a responsive grid layout?

a)

display: flex;

b)

display: grid;

c)

position: absolute;

d)

width: 100%;

18.

Which function executes repeatedly at a given time interval?

a)

setInterval()

b)

setTimeout()

c)

clearTimeout()

d)

requestAnimationFrame()

19.

What does Object.freeze(obj); do?

a)

Makes obj immutable

b)

Deletes obj

c)

Copies obj

d)

Prevents obj from being used

20.

Which function returns the first element that matches a condition in an array?

a)

map()

b)

filter()

c)

find()

d)

some()

21.

What will be logged by the following JavaScript code?

console.log(0.1 + 0.2 === 0.3);

a)

true

b)

false

c)

undefined

d)

NaN

22.

What does the reduce() method do in JavaScript?

a)

Removes duplicate elements from an array

b)

Iterates through an array and reduces it to a single value

c)

Sorts an array

d)

Removes elements from an array

23.

What is the output of this JavaScript code?

console.log(typeof null);

a)

null

b)

object

c)

undefined

d)

NaN

24.

What is the purpose of bind() in JavaScript?

a)

It permanently binds this to a function

b)

It calls a function immediately

c)

It removes this from a function

d)

It clones a function

25.

What will be the output of this JavaScript function?

function foo() {

return {

name: "John"

};

}

console.log(foo());

a)

undefined

b)

SyntaxError

c)

{ name: "John" }

d)

null

26.

Which CSS property controls text overflow when content exceeds its container?

a)

overflow: hidden;

b)

text-overflow: ellipsis;

c)

white-space: nowrap;

d)

All of the above

27.

What does z-index control in CSS?

a)

Transparency of an element

b)

Positioning of an element in 3D space

c)

Stacking order of overlapping elements

d)

The display type of an element

28.

Which property makes an element disappear but keeps its space occupied?

a)

display: none;

b)

opacity: 0;

c)
  • visibility: hidden;

d)

z-index: -1;

29.

What is the difference between inline, inline-block, and block elements in CSS?

a)

inline elements cannot set width or height, block elements take up full width, and inline-block allows width/height

b)

inline and inline-block are identical

c)

block elements are always hidden by default

d)

None of the above

30.

What is the correct syntax for a CSS media query that applies styles only when the screen width is 768px or smaller?

a)

@media (max-width: 768px) { ... }

b)

@media (min-width: 768px) { ... }

c)

@media screen and (max-width: 768px) { ... }

d)

Both A & C