wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Basics Worksheet

Total questions: 150

Worksheet time: 1hrs 15mins

Name
Class
Date
1.

Which of the following best describes JavaScript?

a)

A lightweight scripting language

b)

A markup language

c)

A server-side language

d)

A database language

2.

Which of the following correctly declares a variable in JavaScript?

a)

variable x = 10;

b)

dim x = 10;

c)

let x = 10;

d)

var x == 10;

3.

Which keyword is used to define a constant in JavaScript?

a)

const

b)

static

c)

let

d)

define

4.

Which operator is used to compare both value and type in JavaScript?

a)

==

b)

!=

c)

>=

d)

===

5.

Which built-in method displays a message box to the user?

a)

alert()

b)

show()

c)

display()

d)

prompt()

6.

What will typeof null return in JavaScript?

a)

"null"

b)

"object"

c)

"undefined"

d)

"string"

7.

Which statement is used to stop a loop prematurely?

a)

end

b)

break

c)

stop

d)

continue

8.

What will console.log(2 + "2") output?

a)

4

b)

NaN

c)

"22"

d)

undefined

9.

Which of the following is used to write comments in JavaScript?

a)

// comment

b)

c)

# comment

d)

/* comment */

10.

Which of the following represents a function declaration in JavaScript?

a)

function add(a,b){return a+b;}

b)

func add(a,b){return a+b;}

c)

function:add(a,b)

d)

create function add(a,b)

11.

What does lexical scope define in JavaScript?

a)

Where variables are accessible

b)

How functions are called

c)

The order of execution

d)

The type of each variable

12.

What is the role of a closure?

a)

It hides functions to forget and unuse variables even after the outer function ends

b)

It deletes outer variables to remove variables after the outer function ends

c)

It blocks nested functions to prevent variables act after the outer function ends

d)

It allows functions to remember and use variables even after the outer function ends

13.

What is a prototype in JavaScript?

a)

A private internal link to another object

b)

A class used for inheritance

c)

A data container

d)

A method that deletes objects

14.

______ is code that must wait for the result.

a)

Consuming code

b)

Producing code

c)

Blocking code

d)

Returning code

15.

What describes Synchronous JavaScript correctly?

a)

Runs code line by line, waiting for each task to finish

b)

Executes multiple tasks at once

c)

Runs only async functions

d)

Skips long tasks automatically

16.

What is Asynchronous JavaScript designed to do?

a)

Block all running tasks

b)

Allow multiple tasks to happen without waiting for one to finish

c)

Run only in web workers

d)

Wait for every function to complete

17.

What is a callback function?

a)

A function passed into another function to be executed later

b)

A built-in JavaScript API

c)

A method used to handle exceptions

d)

A variable that stores functions

18.

Why should developers use throw with clear, actionable error objects?

a)

To catch runtime exceptions automatically

b)

To skip invalid code

c)

To signal impossible states early with context for error handlers

d)

To restart the program

19.

What do JavaScript modules allow developers to do?

a)

Break up code into separate, reusable files

b)

Merge all code into one file

c)

Convert code into JSON

d)

Run synchronous loops faster

20.

What is the main purpose of a Promise?

a)

To link producing and consuming code

b)

To store values permanently

c)

To replace functions

d)

To block asynchronous execution

21.

jQuery is primarily used for:

a)

CSS preprocessing

b)

Database queries

c)

HTML templating

d)

Simplifying JavaScript and DOM manipulation

22.

What symbol is used as a shortcut for jQuery?

a)

$

b)

#

c)

@

d)

%

23.

Which of the following loads jQuery into an HTML page?

a)

b)

c)

d)

24.

What does the $(document).ready() function ensure?

a)

The DOM is fully loaded before scripts run

b)

The document reloads

c)

jQuery is disabled

d)

The page resets

25.

Which jQuery selector selects all paragraph elements?

a)

$("p")

b)

$("#p")

c)

$(".p")

d)

$("paragraph")

26.

What does hide() do in jQuery?

a)

Removes an element

b)

Hides selected elements

c)

Deletes nodes

d)

Minimizes script

27.

Which jQuery function is used to change HTML content?

a)

.text()

b)

.set()

c)

.modify()

d)

.change()

28.

What method is used to apply CSS styles using jQuery?

a)

.css()

b)

.style()

c)

.add()

d)

.attr()

29.

Which selector targets an element with the ID "main"?

a)

$("#main")

b)

$(".main")

c)

$("main")

d)

$main

30.

Which event occurs when a user clicks an element?

a)

onPress

b)

onClick

c)

click()

d)

press()

31.

The fadeIn() method in jQuery is used to:

a)

Create a new element

b)

Fade elements into view

c)

Change background color

d)

Remove fade effect

32.

Which method removes selected elements from the DOM?

a)

.clear()

b)

.delete()

c)

.remove()

d)

.vanish()

33.

What does slideToggle() do?

a)

Toggles sliding up and down

b)

Shows only

c)

Hides only

34.

What does the .val() method do?

a)

Gets or sets the value of form elements

b)

Validates text

c)

Changes color

d)

Deletes value

35.

Which method is used to get the HTML content of an element?

a)

.text()

b)

.html()

c)

.get()

d)

.fetch()

36.

To set an attribute using jQuery, use:

a)

.setAttr()

b)

.attr()

c)

.prop()

d)

.assign()

37.

The chaining concept in jQuery means:

a)

Executing multiple methods on the same element

b)

Linking HTML files

c)

Repeating scripts

d)

Combining CSS and JS

38.

Which event triggers when an element loses focus?

a)

focusout()

b)

blur()

c)

change()

d)

keyup()

39.

What does $.ajax() do?

a)

Sends asynchronous HTTP requests

b)

Loads CSS

c)

Handles cookies

d)

Connects databases

40.

The .animate() method is used to:

a)

Create custom animations

b)

Play videos

c)

Load text files

d)

Change attributes

41.

What does PHP stand for?

a)

PHP: Hypertext Preprocessor

b)

Personal Home Page

c)

Programming Hypertext Processor

d)

Page Handling Program

42.

PHP code is executed on the ___.

a)

Client

b)

Browser

c)

Database

d)

Server

43.

Which of the following is a valid PHP file extension?

a)

.php

b)

.ph

c)

.html

d)

.phtml

44.

Which PHP superglobal is used to collect form data sent with the POST method?

a)

$_FORM

b)

$_DATA

c)

$_INPUT

d)

$_POST

45.

What does the htmlspecialchars() function do?

a)

Converts special characters to HTML entities

b)

Converts PHP to HTML

c)

Displays special characters

d)

Escapes HTML tags

46.

Which PHP function removes unnecessary characters like spaces and tabs?

a)

stripslashes()

b)

trim()

c)

htmlspecialchars()

d)

str_replace()

47.

Which function removes backslashes from user input data?

a)

strip_tags()

b)

stripslashes()

c)

substr()

d)

strremove()

48.

Which PHP superglobal contains variables passed through the URL?

a)

$_POST

b)

$_FORM

c)

$_GET

d)

$_URL

49.

What is the purpose of $_SERVER["PHP_SELF"] in a form?

a)

It returns the filename of the current script

b)

It validates form input

c)

It displays all server files

d)

It stores POST data

50.

What is Cross-site scripting (XSS)?

a)

A web vulnerability that allows injection of client-side scripts

b)

A PHP validation method

c)

A database connection issue

d)

A form submission error

51.

What is MySQL?

a)

A programming language

b)

A web server

c)

A relational database management system

d)

A markup language

52.

The main purpose of a database is to ___ .

a)

Store only temporary data

b)

Serve multiple applications efficiently

c)

Replace the web server

d)

Translate SQL into HTML

53.

What does a database schema define?

a)

Queries

b)

Structure and organization of data

c)

User permissions

d)

Database backups

54.

Which SQL command retrieves data from a table?

a)

SELECT

b)

UPDATE

c)

INSERT

d)

DELETE

55.

Which SQL statement is used to permanently delete a table?

a)

REMOVE TABLE

b)

DROP DATA

c)

DELETE TABLE

d)

DROP TABLE

56.

MySQL is considered a type of ___ .

a)

RDBMS

b)

DBMS

c)

OS

d)

Web framework

57.

Which SQL command is used to add new records into a table?

a)

UPDATE

b)

INSERT

c)

SELECT

d)

MODIFY

58.

Which SQL command is used to modify existing data in a table?

a)

ALTER

b)

UPDATE

c)

CHANGE

d)

MODIFY

59.

What clause filters records based on a specified condition?

a)

WHERE

b)

ORDER BY

c)

GROUP BY

d)

FILTER

60.

Which SQL clause groups rows that have the same values?

a)

GROUP

b)

UNION

c)

JOIN

d)

GROUP BY

61.

What is Bootstrap primarily used for?

a)

Game development

b)

Backend database management

c)

Graphic design

d)

Responsive web design

62.

Which of the following is the correct Bootstrap CDN link for CSS?

a)

b)

c)

d)

63.

What is the default grid system in Bootstrap based on?

a)

6 columns

b)

12 columns

c)

10 columns

d)

8 columns

64.

Which Bootstrap class centers text inside an element?

a)

.text-right

b)

.text-center

c)

.text-left

d)

.center

65.

Which class adds a primary button style in Bootstrap?

a)

btn btn-primary

b)

button-primary

c)

primary-btn

d)

btn-main

66.

Which Bootstrap class makes an image responsive?

a)

.img-auto

b)

.img-fluid

c)

.image-resize

d)

.img-responsive

67.

Which component is used to create navigation bars in Bootstrap?

a)

.menu

b)

.navbar

c)

.navitem

d)

.navigation

68.

Which class adds padding inside a container in Bootstrap?

a)

.p-3

b)

.pad-3

c)

.padding-3

d)

.px-3

69.

Which Bootstrap class creates a responsive table?

a)

.table

b)

.table-striped

c)

.table-responsive

d)

.table-bordered

70.

What does the "container" class in Bootstrap do?

a)

It centers and provides padding for page content.

b)

It holds the database connection.

c)

It changes the page layout dynamically.

d)

It resizes images automatically.

71.

Which of the following correctly defines an array in JavaScript?

a)

let arr = [1, 2, 3];

b)

let arr = {1, 2, 3};

c)

let arr = (1, 2, 3);

d)

let arr = <1, 2, 3>;

72.

Which JavaScript method adds an element to the end of an array?

a)

push()

b)

pop()

c)

shift()

d)

unshift()

73.

Which JavaScript method removes the first element of an array?

a)

push()

b)

pop()

c)

shift()

d)

unshift()

74.

What will console.log([1,2,3].length) output?

a)

0

b)

3

c)

[1,2,3]

d)

undefined

75.

Which JavaScript keyword defines a block-scoped variable?

a)

var

b)

const

c)

let

d)

static

76.

Which statement creates an object in JavaScript?

a)

let obj = {};

b)

let obj = [];

c)

let obj = ();

d)

let obj = <>;

77.

Which of the following is NOT a valid JavaScript data type?

a)

string

b)

number

c)

boolean

d)

character

78.

Which operator is used to assign a value to a variable in JavaScript?

a)

=

b)

==

c)

===

d)

:=

79.

Which loop executes at least once even if the condition is false?

a)

for

b)

while

c)

do...while

d)

for...in

80.

Which JavaScript method converts a JSON string into an object?

a)

JSON.stringify()

b)

JSON.parse()

c)

JSON.objectify()

d)

JSON.convert()

81.

What does the map() method do in JavaScript?

a)

Filters array elements

b)

Transforms array elements and returns a new array

c)

Iterates without returning

d)

Reduces array to a single value

82.

What is the output of typeof undefined in JavaScript?

a)

undefined

b)

null

83.

Which of the following is a JavaScript falsy value?

a)

"false"

b)

1

c)

0

d)

"0"

84.

What does the this keyword refer to in a method?

a)

The global object

b)

The object that owns the method

c)

The first argument

d)

Undefined

85.

Which method adds a new element to the beginning of an array?

a)

push()

b)

pop()

c)

unshift()

d)

shift()

86.

Which JavaScript function creates a timer that executes a function repeatedly?

a)

setTimeout()

b)

setInterval()

c)

setLoop()

d)

repeatFunction()

87.

Which statement is true about arrow functions?

a)

They have their own this

b)

They cannot be anonymous

c)

They inherit this from their parent scope

d)

They are slower than traditional functions

88.

Which JavaScript method removes the last element from an array?

a)

push()

b)

pop()

c)

shift()

d)

unshift()

89.

Which of the following is NOT a valid way to define a function?

a)

function myFunc() {}

b)

const myFunc = function() {}

c)

const myFunc = () => {}

d)

function: myFunc() {}

90.

What is the purpose of the finally block in a try...catch statement?

a)

Executes only if no error occurs

b)

Executes only if an error occurs

c)

Executes regardless of whether an error occurs

d)

Skips error handling

91.

What does Promise.resolve(5) do?

a)

Returns a rejected Promise

b)

Returns a resolved Promise with value 5

c)

Throws an error

d)

Returns undefined

92.

Which method schedules code to run asynchronously after a delay?

a)

setTimeout()

b)

setInterval()

c)

setAsync()

d)

setDelayed()

93.

Which method in JavaScript can merge two arrays?

a)

combine()

b)

concat()

c)

merge()

d)

append()

94.

Which jQuery method changes the HTML content of selected elements?

a)

.html()

b)

.text()

c)

.val()

d)

.content()

95.

Which jQuery method shows a hidden element?

a)

hide()

b)

show()

c)

toggle()

d)

display()

96.

Which jQuery method attaches an event handler?

a)

attach()

b)

on()

c)

bind()

d)

event()

97.

Which PHP function is used to remove whitespace from both sides of a string?

a)

trim()

b)

strip()

c)

clean()

d)

strip_spaces()

98.

Which PHP superglobal holds URL parameters?

a)

$_POST

b)

$_GET

c)

$_REQUEST

99.

Which SQL command retrieves all columns from a table named users?

a)

SELECT * FROM users;

b)

GET * FROM users;

c)

FETCH * FROM users;

d)

SHOW * FROM users;

100.

Which SQL command permanently deletes a table?

a)

DELETE TABLE users;

b)

DROP TABLE users;

c)

REMOVE TABLE users;

d)

ERASE TABLE users;

101.

What is the prototype chain used for in JavaScript?

a)

To link functions to HTML elements

b)

To implement inheritance by linking objects

c)

To store global variables

d)

To manage event listeners

102.

Which keyword creates a new object instance from a constructor function?

a)

make

b)

new

c)

create

d)

instance

103.

Which array method returns a new array with elements that pass a test?

a)

forEach()

b)

map()

c)

filter()

d)

reduce()

104.

Which method executes a function on each array element and returns nothing?

a)

map()

b)

forEach()

c)

filter()

d)

some()

105.

Which Promise method executes when all promises succeed?

a)

Promise.any()

b)

Promise.race()

c)

Promise.all()

d)

Promise.resolve()

106.

Which Promise method returns the first fulfilled promise?

a)

Promise.all()

b)

Promise.race()

c)

Promise.any()

d)

Promise.resolve()

107.

Which of these creates a resolved Promise with value 42?

a)

new Promise(42)

b)

Promise.resolve(42)

c)

Promise.create(42)

d)

Promise.done(42)

108.

What does try...catch...finally allow you to do?

a)

Only catch syntax errors

b)

Execute code and handle exceptions, and run cleanup code regardless of outcome

c)

Stop code execution permanently

d)

Convert errors to warnings automatically

109.

Which pattern avoids deeply nested callbacks when chaining asynchronous operations?

a)

Callback hell

b)

Promise chaining / async-await

c)

Synchronous loops

d)

Immediate functions

110.

Which statement correctly exports a default function in ES6 modules?

a)

export default function myFunc() {}

b)

module.exports = myFunc;

c)

export function default myFunc() {}

d)

default export myFunc();

111.

Which statement correctly imports a default export named myFunc from './util.js'?

a)

import { myFunc } from './util.js';

b)

import myFunc from './util.js';

c)

require('./util.js').myFunc;

d)

include './util.js' as myFunc;

112.

What is a memory leak in JavaScript?

a)

When functions return wrong values

b)

When unused memory is not released due to lingering references

c)

When console.log prints too much data

d)

When variables change type unexpectedly

113.

Which jQuery method is commonly used to create plugins by extending jQuery's prototype?

a)

$.plugin()

b)

$.fn.extend()

c)

$.extendPlugin()

d)

$.pluginify()

114.

Which HTML attribute and jQuery method are commonly used together to validate required form fields?

a)

data-required + .check()

b)

required + .val()

c)

validation + .verify()

d)

must + .validate()

115.

Which PHP function is used to start a session?

a)

session_start()

b)

start_session()

c)

begin_session()

d)

open_session()

116.

In PHP, which operator concatenates strings?

a)

+

b)

.

c)

&

d)

concat()

117.

Which SQL clause limits the number of rows returned by a query?

a)

TOP

b)

LIMIT

c)

ROWNUM

d)

BOUND

118.

Which SQL statement creates a new table?

a)

NEW TABLE students (...)

b)

MAKE TABLE students (...)

c)

CREATE TABLE students (...)

d)

BUILD TABLE students (...)

119.

In Bootstrap, which class makes an element only visible on small screens?

a)

d-none d-sm-block

b)

d-block d-sm-none

c)

visible-sm

d)

show-sm

120.

Which JavaScript method creates a shallow copy of an array?

a)

array.clone()

b)

array.slice()

c)

array.copy()

d)

array.duplicate()

121.

Which JavaScript method combines the values of an array into a string?

a)

join()

b)

concat()

c)

merge()

d)

combine()

122.

What will typeof NaN return in JavaScript?

a)

number

b)

NaN

c)

object

d)

undefined

123.

Which jQuery method hides selected elements with a fade effect?

a)

fadeOut()

b)

hide()

c)

toggle()

d)

vanish()

124.

Which method in JavaScript removes whitespace from both ends of a string?

a)

strip()

b)

trim()

c)

clean()

d)

cut()

125.

Which JavaScript operator checks equality without type coercion?

a)

===

b)

==

c)

!=

d)

!==

126.

Which Bootstrap class creates a responsive fixed-width container?

a)

.container

b)

.container-fluid

c)

.row

d)

.col

127.

Which PHP function converts a string to all lowercase letters?

a)

strtolower()

b)

strlower()

c)

lower()

d)

lowercase()

128.

Which SQL statement updates existing records in a table?

a)

MODIFY

b)

UPDATE

c)

CHANGE

d)

ALTER

129.

Which JavaScript method removes a property from an object?

a)

delete obj.prop

b)

remove(obj.prop)

c)

obj.prop.remove()

130.

Which jQuery method toggles the visibility of elements?

a)

hide()

b)

toggle()

c)

show()

d)

display()

131.

Which PHP function removes HTML and PHP tags from a string?

a)

strip_tags()

b)

stripslashes()

c)

trim()

d)

htmlspecialchars()

132.

Which JavaScript method executes a function for every array element and returns a new array?

a)

forEach()

b)

map()

c)

filter()

d)

reduce()

133.

Which Bootstrap class creates a responsive table with horizontal scrolling?

a)

.table

b)

.table-striped

c)

.table-responsive

d)

.table-bordered

134.

Which SQL command removes all records from a table but keeps the structure?

a)

DELETE

b)

DROP

c)

TRUNCATE

d)

REMOVE

135.

Which jQuery method gets the value of form elements?

a)

.val()

b)

.value()

c)

.text()

d)

.html()

136.

Which PHP function checks if a variable is set and is not NULL?

a)

isset()

b)

isnull()

c)

empty()

d)

defined()

137.

Which JavaScript method converts an object to a JSON string?

a)

JSON.stringify()

b)

JSON.parse()

c)

Object.toString()

d)

Object.stringify()

138.

Which Bootstrap class adds spacing inside an element?

a)

.m-3

b)

.p-3

c)

.px-3

d)

.py-3

139.

Which JavaScript method removes the first element of an array?

a)

pop()

b)

push()

c)

shift()

d)

unshift()

140.

Which jQuery method is used to load data from the server without reloading the page?

a)

.ajax()

b)

.loadData()

c)

.getData()

d)

.fetch()

141.

Which PHP function removes backslashes from a string?

a)

strip_tags()

b)

stripslashes()

c)

trim()

d)

htmlspecialchars()

142.

Which JavaScript array method executes a reducer function to reduce an array to a single value?

a)

map()

b)

reduce()

c)

filter()

d)

forEach()

143.

Which Bootstrap class styles a button as secondary?

a)

btn btn-secondary

b)

btn-secondary

c)

secondary-btn

d)

button-secondary

144.

Which JavaScript operator multiplies two numbers?

a)

x

b)

*

c)

×

d)

**

145.

Which PHP superglobal contains information about headers, paths, and script locations?

a)

$_SERVER

b)

$_ENV

c)

$_REQUEST

d)

$_FILES

146.

Which jQuery method adds one or more class names to selected elements?

a)

addClass()

b)

add()

c)

classAdd()

d)

appendClass()

147.

Which JavaScript statement creates a block scope?

a)

function

b)

var

c)

let / const

d)

static

148.

Which SQL clause sorts the results of a query?

a)

WHERE

b)

ORDER BY

c)

GROUP BY

d)

SORT

149.

Which JavaScript method returns the index of the first occurrence of a value in an array?

a)

index()

b)

findIndex()

c)

find()

d)

indexOf()

150.

Which Bootstrap class creates a responsive column layout inside a row?

a)

.col

b)

.row

c)

.container

d)

.grid