Unit 5 - Practice Quiz

CSE326 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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

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

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

A. myFunction()
B. call 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. output
D. return

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

A. undefined
B. false
C. 0
D. null

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 continues until the last line
C. The function prints the value
D. The function stops executing immediately

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

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

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

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

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

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

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. 0
B. false
C. null
D. true

12 Which event fires when an input field loses focus?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. element.focus()
B. element.highlight()
C. element.select()
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 function
D. The element itself

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

31 Which event is triggered when a form is reset?

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

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

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

33 Can a JavaScript function return another function?

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

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

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

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

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

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

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

37 Which of the following is an anonymous function?

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

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

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

39 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

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

A. 0
B. undefined
C. null
D. void

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

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

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

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

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

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

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

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

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. Use type='text'
C. Disable the keyboard
D. Check if event.key is 'Number'

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

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

47 What is passed to the event handler function if defined as 'element.onclick = myFunction;'?

A. The document
B. Nothing
C. The Event object
D. The element

48 Which function converts a string argument to an integer?

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

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

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

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

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