Unit 5 - Practice Quiz

CSE326

1 Which keyword is used to define a function in JavaScript?

A. func
B. def
C. function
D. method

2 What is the correct syntax to call a function named 'myFunction'?

A. call myFunction()
B. myFunction()
C. call function myFunction()
D. myFunction

3 Which statement is used to return a value from a JavaScript function?

A. send
B. value
C. return
D. output

4 If a function is called with fewer arguments than declared parameters, what value are the missing parameters assigned?

A. null
B.
C. undefined
D. false

5 Which built-in object within a function contains an array-like list of all arguments passed to that function?

A. parameters
B. args
C. arguments
D. list

6 What happens when a return statement is executed inside a function?

A. The function restarts
B. The function stops executing immediately
C. The function continues until the last line
D. The function prints the value

7 Which event occurs when the user clicks on an HTML element?

A. onchange
B. onmouseclick
C. onclick
D. onmouseover

8 Which event is triggered when the mouse pointer moves over an element?

A. onhover
B. onmouseover
C. onmouseenter
D. onmove

9 Which event is triggered when the mouse pointer moves out of an element?

A. onmouseout
B. onmouseleave
C. onexit
D. onmouseoff

10 Which event handler is used to execute code when a user submits a form?

A. onclick
B. onexecute
C. onsubmit
D. onsend

11 In form validation, what should the 'onsubmit' event handler return to prevent the form from submitting?

A. true
B. null
C. false
D.

12 Which event fires when an input field loses focus?

A. onfocus
B. onblur
C. onchange
D. onstop

13 Which event fires immediately when an input field gets focus?

A. onfocus
B. onblur
C. onselect
D. onclick

14 Which event is triggered when the content of a form element, the selection, or the checked state have changed?

A. oninput
B. onmodify
C. onchange
D. onblur

15 Which event occurs when the user presses a key on the keyboard?

A. onkeypress
B. onkeydown
C. onkeyup
D. All of the above

16 Which property of the event object returns the Unicode character code of the key that triggered the onkeypress event?

A. keyChar
B. unicode
C. keyCode
D. keyType

17 Which event is triggered when a user releases a key?

A. onkeydown
B. onkeypress
C. onkeyup
D. onkeyrelease

18 How can you access the value of an input field with id='email' in JavaScript?

A. document.getElementById('email').text
B. document.getElementById('email').value
C. document.getElementById('email').content
D. document.getElement('email').value

19 Which function is commonly used to check if a value is not a number during validation?

A. isNumber()
B. isNaN()
C. checkNumber()
D. validateNumber()

20 To set the focus to a specific element in validation, which method is used?

A. element.focus()
B. element.select()
C. element.highlight()
D. element.active()

21 What is the 'this' keyword usually referring to inside an HTML event attribute (e.g., onclick='func(this)')?

A. The window object
B. The document object
C. The element itself
D. The function

22 Which event occurs when a user double-clicks on an element?

A. onclick2
B. ondoubleclick
C. ondblclick
D. on2click

23 Which event occurs when a web page has finished loading?

A. onstart
B. onload
C. onready
D. onfinish

24 Which event is triggered when text is selected in an input or textarea?

A. onhighlight
B. onchoose
C. onselect
D. onmark

25 Which method is used to test if a string matches a regular expression pattern?

A. check()
B. validate()
C. test()
D. verify()

26 When validating an email, which logic is best to check for the presence of '@'?

A. email.length > 0
B. email.indexOf('@') > -1
C. email.value == '@'
D. email.contains('@')

27 What is the correct way to access a form named 'loginForm' via the document object?

A. document.loginForm
B. document.forms['loginForm']
C. Both A and B
D. document.getForm('loginForm')

28 Which property indicates the number of characters in a string value of an input field?

A. size
B. count
C. length
D. width

29 Which event handler is best suited for validating a field immediately after the user leaves it?

A. onmouseover
B. onblur
C. onfocus
D. onload

30 What is the purpose of 'event.preventDefault()'?

A. To stop the event from bubbling
B. To prevent the default action of the element
C. To stop the script
D. To refresh the page

31 Which event is triggered when a form is reset?

A. onclear
B. onreset
C. onempty
D. ondelete

32 How do you check if a checkbox with id='agree' is checked?

A. document.getElementById('agree').value == 'on'
B. document.getElementById('agree').checked == true
C. document.getElementById('agree').selected
D. document.getElementById('agree').on

33 Can a JavaScript function return another function?

A. No, never
B. Yes, this is called a closure or higher-order function
C. Only in strict mode
D. Only if it returns a string

34 Which mouse event is fired when a mouse button is pressed down (before releasing)?

A. onmouseup
B. onclick
C. onmousedown
D. onmousepress

35 To validate that a password is at least 8 characters long, which condition is used?

A. password.value.size >= 8
B. password.value.length >= 8
C. password.length >= 8
D. password.val.len >= 8

36 What defines the scope of a variable declared with 'var' inside a function?

A. Global scope
B. Function scope
C. Block scope
D. Document scope

37 Which of the following is an anonymous function?

A. function myFunc() {}
B. var myFunc = function() {}
C. function() {}
D. Both B and C

38 Which regex syntax is used to create a Regular Expression object?

A. /pattern/flags
B. new RegExp('pattern', 'flags')
C. Both A and B
D. RegExp(/pattern/)

39 In a dropdown list (select tag), how do you get the index of the selected option?

A. element.value
B. element.selectedIndex
C. element.optionIndex
D. element.choice

40 What is the default return value of a function that does not have a return statement?

A. null
B.
C. undefined
D. void

41 Which event is commonly used to detect if a user is typing inside a text box?

A. onselect
B. onkeyup
C. onclick
D. onload

42 How can you stop a function execution if a validation error occurs?

A. break
B. stop
C. return false
D. exit

43 Which JavaScript function displays a dialog box with a message and an OK button?

A. prompt()
B. confirm()
C. alert()
D. msg()

44 To check if a radio button is selected, which property do we check?

A. selected
B. toggled
C. checked
D. active

45 When handling the 'onkeypress' event, how can you allow only numbers to be entered?

A. Check if event.keyCode is between 48 and 57
B. Check if event.key is 'Number'
C. Use type='text'
D. Disable the keyboard

46 Which is the correct syntax to bind an event handler in HTML?

A. <button event='myFunc()'>
B. <button onclick='myFunc()'>
C. <button click='myFunc()'>
D. <button do='myFunc()'>

47 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

48 Which function converts a string argument to an integer?

A. toInteger()
B. parseInt()
C. Float()
D. NumberString()

49 In validation, if a field is empty, what does 'field.value' equal?

A. null
B. undefined
C. "" (empty string)
D.

50 What is the order of mouse events when clicking a button?

A. onclick -> onmousedown -> onmouseup
B. onmousedown -> onmouseup -> onclick
C. onmouseup -> onmousedown -> onclick
D. onclick -> onmouseup -> onmousedown