Question 1 of 50
Which keyword is used to define a function in JavaScript?
A
func
B
method
C
function
D
def
Not quite. Try another option.
Answer: function
In JavaScript, the 'function' keyword is used to declare a function.
Question 2 of 50
What is the correct syntax to call a function named 'myFunction'?
A
call myFunction()
B
call function myFunction()
C
myFunction()
D
myFunction
Not quite. Try another option.
Answer: myFunction()
A function is executed (called) by using its name followed by parentheses.
Question 3 of 50
Which statement is used to return a value from a JavaScript function?
A
return
B
value
C
output
D
send
Not quite. Try another option.
Answer: return
The 'return' statement stops the execution of a function and returns a value to the function caller.
Question 4 of 50
If a function is called with fewer arguments than declared parameters, what value are the missing parameters assigned?
A
false
B
null
C
0
D
undefined
Not quite. Try another option.
Answer: undefined
In JavaScript, if a function is called with missing arguments, the corresponding parameters are set to 'undefined'.
Question 5 of 50
Which built-in object within a function contains an array-like list of all arguments passed to that function?
A
arguments
B
args
C
parameters
D
list
Not quite. Try another option.
Answer: arguments
JavaScript functions have a built-in object called 'arguments' containing an array of arguments used when the function was invoked.
Question 6 of 50
What happens when a return statement is executed inside a function?
A
The function continues until the last line
B
The function prints the value
C
The function restarts
D
The function stops executing immediately
Not quite. Try another option.
Answer: The function stops executing immediately
When JavaScript reaches a return statement, the function will stop executing.
Question 7 of 50
Which event occurs when the user clicks on an HTML element?
A
onclick
B
onmouseover
C
onmouseclick
D
onchange
Not quite. Try another option.
Answer: onclick
The 'onclick' event occurs when the user clicks on an element.
Question 8 of 50
Which event is triggered when the mouse pointer moves over an element?
A
onmove
B
onmouseover
C
onmouseenter
D
onhover
Not quite. Try another option.
Answer: onmouseover
The 'onmouseover' event occurs when the mouse pointer is moved onto an element.
Question 9 of 50
Which event is triggered when the mouse pointer moves out of an element?
A
onmouseout
B
onexit
C
onmouseoff
D
onmouseleave
Not quite. Try another option.
Answer: onmouseout
The 'onmouseout' event occurs when the mouse pointer is moved out of an element.
Question 10 of 50
Which event handler is used to execute code when a user submits a form?
A
onsubmit
B
onexecute
C
onclick
D
onsend
Not quite. Try another option.
Answer: onsubmit
The 'onsubmit' event occurs when a form is submitted.
Question 11 of 50
In form validation, what should the 'onsubmit' event handler return to prevent the form from submitting?
A
null
B
true
C
0
D
false
Not quite. Try another option.
Answer: false
Returning 'false' from the onsubmit handler prevents the browser from submitting the form data to the server.
Question 12 of 50
Which event fires when an input field loses focus?
A
onblur
B
onchange
C
onstop
D
onfocus
Not quite. Try another option.
Answer: onblur
The 'onblur' event occurs when an object loses focus.
Question 13 of 50
Which event fires immediately when an input field gets focus?
A
onblur
B
onselect
C
onfocus
D
onclick
Not quite. Try another option.
Answer: onfocus
The 'onfocus' event occurs when an element gets focus.
Question 14 of 50
Which event is triggered when the content of a form element, the selection, or the checked state have changed?
A
onblur
B
oninput
C
onmodify
D
onchange
Not quite. Try another option.
Answer: onchange
The 'onchange' event occurs when the value of an element has been changed.
Question 15 of 50
Which event occurs when the user presses a key on the keyboard?
A
onkeypress
B
All of the above
C
onkeyup
D
onkeydown
Not quite. Try another option.
Answer: All of the above
Keyboard events include onkeydown, onkeypress, and onkeyup.
Question 16 of 50
Which property of the event object returns the Unicode character code of the key that triggered the onkeypress event?
A
keyChar
B
keyCode
C
keyType
D
unicode
Not quite. Try another option.
Answer: keyCode
The 'keyCode' property returns the Unicode character code of the key that triggered the onkeypress event.
Question 17 of 50
Which event is triggered when a user releases a key?
A
onkeypress
B
onkeyrelease
C
onkeyup
D
onkeydown
Not quite. Try another option.
Answer: onkeyup
The 'onkeyup' event occurs when the user releases a key.
Question 18 of 50
How can you access the value of an input field with id='email' in JavaScript?
A
document.getElementById('email').value
B
document.getElementById('email').text
C
document.getElement('email').value
D
document.getElementById('email').content
Not quite. Try another option.
Answer: document.getElementById('email').value
The '.value' property is used to get the current value of an input element.
Question 19 of 50
Which function is commonly used to check if a value is not a number during validation?
A
isNaN()
B
isNumber()
C
validateNumber()
D
checkNumber()
Not quite. Try another option.
Answer: isNaN()
The global isNaN() function determines whether a value is an illegal number (Not-a-Number).
Question 20 of 50
To set the focus to a specific element in validation, which method is used?
A
element.highlight()
B
element.select()
C
element.focus()
D
element.active()
Not quite. Try another option.
Answer: element.focus()
The .focus() method is used to give focus to an HTML element.
Question 21 of 50
What is the 'this' keyword usually referring to inside an HTML event attribute (e.g., onclick='func(this)')?
A
The window object
B
The element itself
C
The function
D
The document object
Not quite. Try another option.
Answer: The element itself
In an HTML event handler, 'this' refers to the HTML element that received the event.
Question 22 of 50
Which event occurs when a user double-clicks on an element?
A
ondoubleclick
B
on2click
C
ondblclick
D
onclick2
Not quite. Try another option.
Answer: ondblclick
The 'ondblclick' event occurs when the user double-clicks on an element.
Question 23 of 50
Which event occurs when a web page has finished loading?
A
onload
B
onfinish
C
onready
D
onstart
Not quite. Try another option.
Answer: onload
The 'onload' event occurs when an object (like the body/page) has been loaded.
Question 24 of 50
Which event is triggered when text is selected in an input or textarea?
A
onselect
B
onmark
C
onchoose
D
onhighlight
Not quite. Try another option.
Answer: onselect
The 'onselect' event occurs after some text has been selected in an element.
Question 25 of 50
Which method is used to test if a string matches a regular expression pattern?
A
test()
B
validate()
C
check()
D
verify()
Not quite. Try another option.
Answer: test()
The RegExp test() method checks for a match in a string and returns true or false.
Question 26 of 50
When validating an email, which logic is best to check for the presence of '@'?
A
email.value == '@'
B
email.contains('@')
C
email.length > 0
D
email.indexOf('@') > -1
Not quite. Try another option.
Answer: email.indexOf('@') > -1
indexOf('@') returns the position of the character. If it returns -1, the character is not found.
Question 27 of 50
What is the correct way to access a form named 'loginForm' via the document object?
A
document.getForm('loginForm')
B
document.loginForm
C
Both A and B
D
document.forms['loginForm']
Not quite. Try another option.
Answer: Both A and B
Forms can be accessed directly by name as a property of document or via the forms collection.
Question 28 of 50
Which property indicates the number of characters in a string value of an input field?
A
width
B
length
C
size
D
count
Not quite. Try another option.
Answer: length
String values have a 'length' property that returns the number of characters.
Question 29 of 50
Which event handler is best suited for validating a field immediately after the user leaves it?
A
onblur
B
onfocus
C
onload
D
onmouseover
Not quite. Try another option.
Answer: onblur
onblur fires when the user leaves the field, making it ideal for immediate field-level validation.
Question 30 of 50
What is the purpose of 'event.preventDefault()'?
A
To stop the script
B
To prevent the default action of the element
C
To refresh the page
D
To stop the event from bubbling
Not quite. Try another option.
Answer: To prevent the default action of the element
preventDefault() cancels the event if it is cancelable, meaning that the default action (like submitting a form) will not occur.
Question 31 of 50
Which event is triggered when a form is reset?
A
onclear
B
onreset
C
ondelete
D
onempty
Not quite. Try another option.
Answer: onreset
The 'onreset' event occurs when the Reset button in a form is clicked.
Question 32 of 50
How do you check if a checkbox with id='agree' is checked?
A
document.getElementById('agree').checked == true
B
document.getElementById('agree').selected
C
document.getElementById('agree').on
D
document.getElementById('agree').value == 'on'
Not quite. Try another option.
Answer: document.getElementById('agree').checked == true
Checkboxes have a 'checked' boolean property indicating their state.
Question 33 of 50
Can a JavaScript function return another function?
A
Only if it returns a string
B
Only in strict mode
C
No, never
D
Yes, this is called a closure or higher-order function
Not quite. Try another option.
Answer: Yes, this is called a closure or higher-order function
JavaScript functions are first-class citizens and can return other functions.
Question 34 of 50
Which mouse event is fired when a mouse button is pressed down (before releasing)?
A
onmousepress
B
onmousedown
C
onmouseup
D
onclick
Not quite. Try another option.
Answer: onmousedown
The 'onmousedown' event occurs when a mouse button is pressed down over an element.
Question 35 of 50
To validate that a password is at least 8 characters long, which condition is used?
A
password.value.length >= 8
B
password.val.len >= 8
C
password.length >= 8
D
password.value.size >= 8
Not quite. Try another option.
Answer: password.value.length >= 8
You must access the '.value' of the input first, then the '.length' property of that string.
Question 36 of 50
What defines the scope of a variable declared with 'var' inside a function?
A
Document scope
B
Global scope
C
Block scope
D
Function scope
Not quite. Try another option.
Answer: Function scope
Variables declared with 'var' inside a function are local to that function (Function Scope).
Question 37 of 50
Which of the following is an anonymous function?
A
function myFunc() {}
B
Both B and C
C
function() {}
D
var myFunc = function() {}
Not quite. Try another option.
Answer: Both B and C
An anonymous function is a function without a name. It can be used in an expression or assigned to a variable.
Question 38 of 50
Which regex syntax is used to create a Regular Expression object?
A
new RegExp('pattern', 'flags')
B
RegExp(/pattern/)
C
/pattern/flags
D
Both A and B
Not quite. Try another option.
Answer: Both A and B
Regular expressions can be created using literal syntax (/.../) or the RegExp constructor.
Question 39 of 50
In a dropdown list (select tag), how do you get the index of the selected option?
A
element.selectedIndex
B
element.choice
C
element.optionIndex
D
element.value
Not quite. Try another option.
Answer: element.selectedIndex
The 'selectedIndex' property sets or returns the index of the selected option in a drop-down list.
Question 40 of 50
What is the default return value of a function that does not have a return statement?
A
null
B
0
C
undefined
D
void
Not quite. Try another option.
Answer: undefined
If a function does not return a value, it returns 'undefined' by default.
Question 41 of 50
Which event is commonly used to detect if a user is typing inside a text box?
A
onselect
B
onload
C
onclick
D
onkeyup
Not quite. Try another option.
Answer: onkeyup
onkeyup (or oninput) is commonly used to trigger code as the user types.
Question 42 of 50
How can you stop a function execution if a validation error occurs?
A
return false
B
stop
C
break
D
exit
Not quite. Try another option.
Answer: return false
Returning 'false' is the standard way to indicate failure in a validation function and stop subsequent logic (often used to stop form submission).
Question 43 of 50
Which JavaScript function displays a dialog box with a message and an OK button?
A
msg()
B
confirm()
C
alert()
D
prompt()
Not quite. Try another option.
Answer: alert()
The alert() method displays an alert box with a specified message and an OK button.
Question 44 of 50
To check if a radio button is selected, which property do we check?
A
toggled
B
checked
C
selected
D
active
Not quite. Try another option.
Answer: checked
Radio buttons, like checkboxes, use the 'checked' property.
Question 45 of 50
When handling the 'onkeypress' event, how can you allow only numbers to be entered?
A
Disable the keyboard
B
Use type='text'
C
Check if event.keyCode is between 48 and 57
D
Check if event.key is 'Number'
Not quite. Try another option.
Answer: Check if event.keyCode is between 48 and 57
ASCII codes 48 to 57 correspond to digits 0-9. Checking keyCode allows blocking non-numeric input.
Question 46 of 50
Which is the correct syntax to bind an event handler in HTML?
A
<button onclick='myFunc()'>
B
<button event='myFunc()'>
C
<button click='myFunc()'>
D
<button do='myFunc()'>
Not quite. Try another option.
Answer: <button onclick='myFunc()'>
The standard HTML attribute syntax for a click event is onclick='...'.
Question 47 of 50
What is passed to the event handler function if defined as 'element.onclick = myFunction;'?
A
Nothing
B
The Event object
C
The element
D
The document
Not quite. Try another option.
Answer: The Event object
When assigning a function to an event property in JS, the browser automatically passes the event object as the first argument.
Question 48 of 50
Which function converts a string argument to an integer?
A
Float()
B
toInteger()
C
NumberString()
D
parseInt()
Not quite. Try another option.
Answer: parseInt()
The parseInt() function parses a string argument and returns an integer.
Question 49 of 50
In validation, if a field is empty, what does 'field.value' equal?
A
"" (empty string)
B
0
C
undefined
D
null
Not quite. Try another option.
Answer: "" (empty string)
An empty HTML input field returns an empty string ("") via the .value property.
Question 50 of 50
What is the order of mouse events when clicking a button?
A
onclick -> onmouseup -> onmousedown
B
onclick -> onmousedown -> onmouseup
C
onmousedown -> onmouseup -> onclick
D
onmouseup -> onmousedown -> onclick
Not quite. Try another option.
Answer: onmousedown -> onmouseup -> onclick
The sequence is: mouse button goes down, mouse button goes up, then the click event is fired.