Form Validation Basics
Which JavaScript method can be used to prevent a form from submitting if certain fields are invalid?
- preventFormAction()
- event.blockDefault()
- event.preventDefault()
- stopSubmission()
- form.cancelSubmit()
Accessing Local Storage
What method would you use to store a value 'hello' under the key 'greeting' in the browser's local storage?
- localStorage.setItem('greeting', 'hello')
- localStorage.addItem('greeting', 'hello')
- localStorage.save('greeting', 'hello')
- sessionStorage.setValue('greeting', 'hello')
- localStorage.put('greeting', 'hello')
Getting Input Value
Given an input field with id='user', how can you retrieve its value with JavaScript?
- document.input('user').value
- document.getInputById('user').val()
- document.value('user').get()
- document.getElementById('user').value
- getElementById('user').content
Checking Local Storage Support
Which JavaScript feature should you check to confirm if the browser supports local storage?
- window.sessionCookies
- browser.localStorageSupport
- localStorageEnabled
- window.localStorage
- window.hasLocalData
Reading a Cookie Value
How do you access all cookies set for the current page in JavaScript?
- window.cookies
- browser.cookies
- document.cookie
- navigator.cookie
- cookie.document
Session Storage Lifetime
What happens to data stored with sessionStorage after you close the browser tab?
- It is saved permanently
- It moves to cookies
- It is transferred to localStorage
- It is deleted automatically
- It is sent to the server
HTML Form Attribute
Which HTML attribute can help trigger the browser's built-in form validation for required fields?
- fillOut
- mustFill
- required
- validateInput
- mandatory
Cookie Expiration
Which cookie attribute specifies when a cookie will be removed automatically?
- expires
- lifetime
- removeAfter
- expiryTime
- timeout
Session Storage Key Retrieval
What method allows you to retrieve the value of a key named 'username' from sessionStorage?
- sessionStorage.find('username')
- sessionStorage.getItem('username')
- sessionStorage.valueOf('username')
- sessionStorage.retrieve('username')
- sessionStorage.get('username')
Removing From Local Storage
If you want to delete the item with key 'token' from local storage, which method should you use?
- localStorage.remove('token')
- localStorage.removeItem('token')
- localStorage.delete('token')
- localStorage.clearItem('token')
- localStorage.forget('token')
Custom Pattern Validation
What HTML attribute can be used to specify a regular expression for input validation?
- validate
- expression
- regex
- pattern
- match
Cookie Path Attribute
Which attribute in a cookie determines which URLs on the domain the cookie is accessible to?
- location
- urlLimit
- scope
- area
- path
Clearing All Local Storage
What method removes all key-value pairs from the browser's local storage at once?
- localStorage.purge()
- localStorage.erase()
- localStorage.clear()
- localStorage.removeAll()
- localStorage.empty()
Difference Between Local and Session Storage
What is a key difference between localStorage and sessionStorage in browsers?
- localStorage cannot store strings
- sessionStorage has larger storage capacity
- sessionStorage is visible to all browser tabs; localStorage is not
- localStorage is faster than sessionStorage
- localStorage persists after closing the browser; sessionStorage does not
Setting a Cookie in JavaScript
How do you set a cookie named 'auth' with value 'yes' using JavaScript?
- setCookie('auth','yes')
- cookie.set('auth','yes')
- document.cookie = 'auth=yes';
- window.cookie = 'auth:yes'
- document.setCookie('auth','yes')