Browser Storage
Storing and retrieving string-based data in the browser.
| Term / Syntax | Name | Description | Example |
|---|---|---|---|
localStorage.setItem() |
Store Persistent Value | Stores a string value under a specified key and keeps it across browser sessions. | localStorage.setItem("theme", "dark"); |
localStorage.getItem() |
Read Persistent Value | Returns the value stored under a specified key, or null if the key does not exist. |
const theme = localStorage.getItem("theme"); |
localStorage.removeItem() |
Remove Persistent Value | Removes the value stored under a specified key. | localStorage.removeItem("theme"); |
localStorage.clear() |
Clear Persistent Storage | Removes all values stored in local storage for the current origin. | localStorage.clear(); |
sessionStorage.setItem() |
Store Session Value | Stores a string value for the current page session. | sessionStorage.setItem("step", "2"); |
sessionStorage.getItem() |
Read Session Value | Returns a session value stored under a specified key, or null if the key does not exist. |
const step = sessionStorage.getItem("step"); |
sessionStorage.removeItem() |
Remove Session Value | Removes the value stored under a specified key for the current page session. | sessionStorage.removeItem("step"); |
JSON.stringify() + localStorage |
Store Structured Data | Converts a JavaScript value to JSON text before storing it in local storage. | localStorage.setItem("user", JSON.stringify(user)); |
JSON.parse() + localStorage |
Read Structured Data | Parses stored JSON text back into a JavaScript value. | const user = JSON.parse(localStorage.getItem("user")); |
Timers
Scheduling code to run after a delay or repeatedly at a specified interval.
| Term / Syntax | Name | Description | Example |
|---|---|---|---|
setTimeout() |
Delayed Execution | Schedules a function to run once after at least the specified delay in milliseconds. | setTimeout(showMessage, 1000); |
clearTimeout() |
Cancel Timeout | Cancels a timeout before its scheduled function runs. | clearTimeout(timeoutId); |
setInterval() |
Repeated Execution | Schedules a function to run repeatedly with approximately the specified delay between executions. | const intervalId = setInterval(updateClock, 1000); |
clearInterval() |
Cancel Interval | Stops a repeating interval created with setInterval(). |
clearInterval(intervalId); |
Browser Information
Reading common information provided by the browser and current viewport.
| Term / Syntax | Name | Description | Example |
|---|---|---|---|
window.innerWidth |
Viewport Width | Returns the width of the browser's layout viewport in CSS pixels. | const width = window.innerWidth; |
window.innerHeight |
Viewport Height | Returns the height of the browser's layout viewport in CSS pixels. | const height = window.innerHeight; |
navigator.language |
Preferred Language | Returns the user's preferred browser language as a language tag. | const language = navigator.language; |
navigator.onLine |
Online Status | Indicates whether the browser reports that a network connection is available. | if (navigator.onLine) { /* connected */ } |