WorksheetsJavaScript Basics Worksheet
Total questions: 150
Worksheet time: 1hrs 15mins
Which of the following best describes JavaScript?
A lightweight scripting language
A markup language
A server-side language
A database language
Which of the following correctly declares a variable in JavaScript?
variable x = 10;
dim x = 10;
let x = 10;
var x == 10;
Which keyword is used to define a constant in JavaScript?
const
static
let
define
Which operator is used to compare both value and type in JavaScript?
==
!=
>=
===
Which built-in method displays a message box to the user?
alert()
show()
display()
prompt()
What will typeof null return in JavaScript?
"null"
"object"
"undefined"
"string"
Which statement is used to stop a loop prematurely?
end
break
stop
continue
What will console.log(2 + "2") output?
4
NaN
"22"
undefined
Which of the following is used to write comments in JavaScript?
// comment
# comment
/* comment */
Which of the following represents a function declaration in JavaScript?
function add(a,b){return a+b;}
func add(a,b){return a+b;}
function:add(a,b)
create function add(a,b)
What does lexical scope define in JavaScript?
Where variables are accessible
How functions are called
The order of execution
The type of each variable
What is the role of a closure?
It hides functions to forget and unuse variables even after the outer function ends
It deletes outer variables to remove variables after the outer function ends
It blocks nested functions to prevent variables act after the outer function ends
It allows functions to remember and use variables even after the outer function ends
What is a prototype in JavaScript?
A private internal link to another object
A class used for inheritance
A data container
A method that deletes objects
______ is code that must wait for the result.
Consuming code
Producing code
Blocking code
Returning code
What describes Synchronous JavaScript correctly?
Runs code line by line, waiting for each task to finish
Executes multiple tasks at once
Runs only async functions
Skips long tasks automatically
What is Asynchronous JavaScript designed to do?
Block all running tasks
Allow multiple tasks to happen without waiting for one to finish
Run only in web workers
Wait for every function to complete
What is a callback function?
A function passed into another function to be executed later
A built-in JavaScript API
A method used to handle exceptions
A variable that stores functions
Why should developers use throw with clear, actionable error objects?
To catch runtime exceptions automatically
To skip invalid code
To signal impossible states early with context for error handlers
To restart the program
What do JavaScript modules allow developers to do?
Break up code into separate, reusable files
Merge all code into one file
Convert code into JSON
Run synchronous loops faster
What is the main purpose of a Promise?
To link producing and consuming code
To store values permanently
To replace functions
To block asynchronous execution
jQuery is primarily used for:
CSS preprocessing
Database queries
HTML templating
Simplifying JavaScript and DOM manipulation
What symbol is used as a shortcut for jQuery?
$
#
@
%
Which of the following loads jQuery into an HTML page?
What does the $(document).ready() function ensure?
The DOM is fully loaded before scripts run
The document reloads
jQuery is disabled
The page resets
Which jQuery selector selects all paragraph elements?
$("p")
$("#p")
$(".p")
$("paragraph")
What does hide() do in jQuery?
Removes an element
Hides selected elements
Deletes nodes
Minimizes script
Which jQuery function is used to change HTML content?
.text()
.set()
.modify()
.change()
What method is used to apply CSS styles using jQuery?
.css()
.style()
.add()
.attr()
Which selector targets an element with the ID "main"?
$("#main")
$(".main")
$("main")
$main
Which event occurs when a user clicks an element?
onPress
onClick
click()
press()
The fadeIn() method in jQuery is used to:
Create a new element
Fade elements into view
Change background color
Remove fade effect
Which method removes selected elements from the DOM?
.clear()
.delete()
.remove()
.vanish()
What does slideToggle() do?
Toggles sliding up and down
Shows only
Hides only
What does the .val() method do?
Gets or sets the value of form elements
Validates text
Changes color
Deletes value
Which method is used to get the HTML content of an element?
.text()
.html()
.get()
.fetch()
To set an attribute using jQuery, use:
.setAttr()
.attr()
.prop()
.assign()
The chaining concept in jQuery means:
Executing multiple methods on the same element
Linking HTML files
Repeating scripts
Combining CSS and JS
Which event triggers when an element loses focus?
focusout()
blur()
change()
keyup()
What does $.ajax() do?
Sends asynchronous HTTP requests
Loads CSS
Handles cookies
Connects databases
The .animate() method is used to:
Create custom animations
Play videos
Load text files
Change attributes
What does PHP stand for?
PHP: Hypertext Preprocessor
Personal Home Page
Programming Hypertext Processor
Page Handling Program
PHP code is executed on the ___.
Client
Browser
Database
Server
Which of the following is a valid PHP file extension?
.php
.ph
.html
.phtml
Which PHP superglobal is used to collect form data sent with the POST method?
$_FORM
$_DATA
$_INPUT
$_POST
What does the htmlspecialchars() function do?
Converts special characters to HTML entities
Converts PHP to HTML
Displays special characters
Escapes HTML tags
Which PHP function removes unnecessary characters like spaces and tabs?
stripslashes()
trim()
htmlspecialchars()
str_replace()
Which function removes backslashes from user input data?
strip_tags()
stripslashes()
substr()
strremove()
Which PHP superglobal contains variables passed through the URL?
$_POST
$_FORM
$_GET
$_URL
What is the purpose of $_SERVER["PHP_SELF"] in a form?
It returns the filename of the current script
It validates form input
It displays all server files
It stores POST data
What is Cross-site scripting (XSS)?
A web vulnerability that allows injection of client-side scripts
A PHP validation method
A database connection issue
A form submission error
What is MySQL?
A programming language
A web server
A relational database management system
A markup language
The main purpose of a database is to ___ .
Store only temporary data
Serve multiple applications efficiently
Replace the web server
Translate SQL into HTML
What does a database schema define?
Queries
Structure and organization of data
User permissions
Database backups
Which SQL command retrieves data from a table?
SELECT
UPDATE
INSERT
DELETE
Which SQL statement is used to permanently delete a table?
REMOVE TABLE
DROP DATA
DELETE TABLE
DROP TABLE
MySQL is considered a type of ___ .
RDBMS
DBMS
OS
Web framework
Which SQL command is used to add new records into a table?
UPDATE
INSERT
SELECT
MODIFY
Which SQL command is used to modify existing data in a table?
ALTER
UPDATE
CHANGE
MODIFY
What clause filters records based on a specified condition?
WHERE
ORDER BY
GROUP BY
FILTER
Which SQL clause groups rows that have the same values?
GROUP
UNION
JOIN
GROUP BY
What is Bootstrap primarily used for?
Game development
Backend database management
Graphic design
Responsive web design
Which of the following is the correct Bootstrap CDN link for CSS?
What is the default grid system in Bootstrap based on?
6 columns
12 columns
10 columns
8 columns
Which Bootstrap class centers text inside an element?
.text-right
.text-center
.text-left
.center
Which class adds a primary button style in Bootstrap?
btn btn-primary
button-primary
primary-btn
btn-main
Which Bootstrap class makes an image responsive?
.img-auto
.img-fluid
.image-resize
.img-responsive
Which component is used to create navigation bars in Bootstrap?
.menu
.navbar
.navitem
.navigation
Which class adds padding inside a container in Bootstrap?
.p-3
.pad-3
.padding-3
.px-3
Which Bootstrap class creates a responsive table?
.table
.table-striped
.table-responsive
.table-bordered
What does the "container" class in Bootstrap do?
It centers and provides padding for page content.
It holds the database connection.
It changes the page layout dynamically.
It resizes images automatically.
Which of the following correctly defines an array in JavaScript?
let arr = [1, 2, 3];
let arr = {1, 2, 3};
let arr = (1, 2, 3);
let arr = <1, 2, 3>;
Which JavaScript method adds an element to the end of an array?
push()
pop()
shift()
unshift()
Which JavaScript method removes the first element of an array?
push()
pop()
shift()
unshift()
What will console.log([1,2,3].length) output?
0
3
[1,2,3]
undefined
Which JavaScript keyword defines a block-scoped variable?
var
const
let
static
Which statement creates an object in JavaScript?
let obj = {};
let obj = [];
let obj = ();
let obj = <>;
Which of the following is NOT a valid JavaScript data type?
string
number
boolean
character
Which operator is used to assign a value to a variable in JavaScript?
=
==
===
:=
Which loop executes at least once even if the condition is false?
for
while
do...while
for...in
Which JavaScript method converts a JSON string into an object?
JSON.stringify()
JSON.parse()
JSON.objectify()
JSON.convert()
What does the map() method do in JavaScript?
Filters array elements
Transforms array elements and returns a new array
Iterates without returning
Reduces array to a single value
What is the output of typeof undefined in JavaScript?
undefined
null
Which of the following is a JavaScript falsy value?
"false"
1
0
"0"
What does the this keyword refer to in a method?
The global object
The object that owns the method
The first argument
Undefined
Which method adds a new element to the beginning of an array?
push()
pop()
unshift()
shift()
Which JavaScript function creates a timer that executes a function repeatedly?
setTimeout()
setInterval()
setLoop()
repeatFunction()
Which statement is true about arrow functions?
They have their own this
They cannot be anonymous
They inherit this from their parent scope
They are slower than traditional functions
Which JavaScript method removes the last element from an array?
push()
pop()
shift()
unshift()
Which of the following is NOT a valid way to define a function?
function myFunc() {}
const myFunc = function() {}
const myFunc = () => {}
function: myFunc() {}
What is the purpose of the finally block in a try...catch statement?
Executes only if no error occurs
Executes only if an error occurs
Executes regardless of whether an error occurs
Skips error handling
What does Promise.resolve(5) do?
Returns a rejected Promise
Returns a resolved Promise with value 5
Throws an error
Returns undefined
Which method schedules code to run asynchronously after a delay?
setTimeout()
setInterval()
setAsync()
setDelayed()
Which method in JavaScript can merge two arrays?
combine()
concat()
merge()
append()
Which jQuery method changes the HTML content of selected elements?
.html()
.text()
.val()
.content()
Which jQuery method shows a hidden element?
hide()
show()
toggle()
display()
Which jQuery method attaches an event handler?
attach()
on()
bind()
event()
Which PHP function is used to remove whitespace from both sides of a string?
trim()
strip()
clean()
strip_spaces()
Which PHP superglobal holds URL parameters?
$_POST
$_GET
$_REQUEST
Which SQL command retrieves all columns from a table named users?
SELECT * FROM users;
GET * FROM users;
FETCH * FROM users;
SHOW * FROM users;
Which SQL command permanently deletes a table?
DELETE TABLE users;
DROP TABLE users;
REMOVE TABLE users;
ERASE TABLE users;
What is the prototype chain used for in JavaScript?
To link functions to HTML elements
To implement inheritance by linking objects
To store global variables
To manage event listeners
Which keyword creates a new object instance from a constructor function?
make
new
create
instance
Which array method returns a new array with elements that pass a test?
forEach()
map()
filter()
reduce()
Which method executes a function on each array element and returns nothing?
map()
forEach()
filter()
some()
Which Promise method executes when all promises succeed?
Promise.any()
Promise.race()
Promise.all()
Promise.resolve()
Which Promise method returns the first fulfilled promise?
Promise.all()
Promise.race()
Promise.any()
Promise.resolve()
Which of these creates a resolved Promise with value 42?
new Promise(42)
Promise.resolve(42)
Promise.create(42)
Promise.done(42)
What does try...catch...finally allow you to do?
Only catch syntax errors
Execute code and handle exceptions, and run cleanup code regardless of outcome
Stop code execution permanently
Convert errors to warnings automatically
Which pattern avoids deeply nested callbacks when chaining asynchronous operations?
Callback hell
Promise chaining / async-await
Synchronous loops
Immediate functions
Which statement correctly exports a default function in ES6 modules?
export default function myFunc() {}
module.exports = myFunc;
export function default myFunc() {}
default export myFunc();
Which statement correctly imports a default export named myFunc from './util.js'?
import { myFunc } from './util.js';
import myFunc from './util.js';
require('./util.js').myFunc;
include './util.js' as myFunc;
What is a memory leak in JavaScript?
When functions return wrong values
When unused memory is not released due to lingering references
When console.log prints too much data
When variables change type unexpectedly
Which jQuery method is commonly used to create plugins by extending jQuery's prototype?
$.plugin()
$.fn.extend()
$.extendPlugin()
$.pluginify()
Which HTML attribute and jQuery method are commonly used together to validate required form fields?
data-required + .check()
required + .val()
validation + .verify()
must + .validate()
Which PHP function is used to start a session?
session_start()
start_session()
begin_session()
open_session()
In PHP, which operator concatenates strings?
+
.
&
concat()
Which SQL clause limits the number of rows returned by a query?
TOP
LIMIT
ROWNUM
BOUND
Which SQL statement creates a new table?
NEW TABLE students (...)
MAKE TABLE students (...)
CREATE TABLE students (...)
BUILD TABLE students (...)
In Bootstrap, which class makes an element only visible on small screens?
d-none d-sm-block
d-block d-sm-none
visible-sm
show-sm
Which JavaScript method creates a shallow copy of an array?
array.clone()
array.slice()
array.copy()
array.duplicate()
Which JavaScript method combines the values of an array into a string?
join()
concat()
merge()
combine()
What will typeof NaN return in JavaScript?
number
NaN
object
undefined
Which jQuery method hides selected elements with a fade effect?
fadeOut()
hide()
toggle()
vanish()
Which method in JavaScript removes whitespace from both ends of a string?
strip()
trim()
clean()
cut()
Which JavaScript operator checks equality without type coercion?
===
==
!=
!==
Which Bootstrap class creates a responsive fixed-width container?
.container
.container-fluid
.row
.col
Which PHP function converts a string to all lowercase letters?
strtolower()
strlower()
lower()
lowercase()
Which SQL statement updates existing records in a table?
MODIFY
UPDATE
CHANGE
ALTER
Which JavaScript method removes a property from an object?
delete obj.prop
remove(obj.prop)
obj.prop.remove()
Which jQuery method toggles the visibility of elements?
hide()
toggle()
show()
display()
Which PHP function removes HTML and PHP tags from a string?
strip_tags()
stripslashes()
trim()
htmlspecialchars()
Which JavaScript method executes a function for every array element and returns a new array?
forEach()
map()
filter()
reduce()
Which Bootstrap class creates a responsive table with horizontal scrolling?
.table
.table-striped
.table-responsive
.table-bordered
Which SQL command removes all records from a table but keeps the structure?
DELETE
DROP
TRUNCATE
REMOVE
Which jQuery method gets the value of form elements?
.val()
.value()
.text()
.html()
Which PHP function checks if a variable is set and is not NULL?
isset()
isnull()
empty()
defined()
Which JavaScript method converts an object to a JSON string?
JSON.stringify()
JSON.parse()
Object.toString()
Object.stringify()
Which Bootstrap class adds spacing inside an element?
.m-3
.p-3
.px-3
.py-3
Which JavaScript method removes the first element of an array?
pop()
push()
shift()
unshift()
Which jQuery method is used to load data from the server without reloading the page?
.ajax()
.loadData()
.getData()
.fetch()
Which PHP function removes backslashes from a string?
strip_tags()
stripslashes()
trim()
htmlspecialchars()
Which JavaScript array method executes a reducer function to reduce an array to a single value?
map()
reduce()
filter()
forEach()
Which Bootstrap class styles a button as secondary?
btn btn-secondary
btn-secondary
secondary-btn
button-secondary
Which JavaScript operator multiplies two numbers?
x
*
×
**
Which PHP superglobal contains information about headers, paths, and script locations?
$_SERVER
$_ENV
$_REQUEST
$_FILES
Which jQuery method adds one or more class names to selected elements?
addClass()
add()
classAdd()
appendClass()
Which JavaScript statement creates a block scope?
function
var
let / const
static
Which SQL clause sorts the results of a query?
WHERE
ORDER BY
GROUP BY
SORT
Which JavaScript method returns the index of the first occurrence of a value in an array?
index()
findIndex()
find()
indexOf()
Which Bootstrap class creates a responsive column layout inside a row?
.col
.row
.container
.grid
