Jul 18, 2024
console.log()
to print messages in the console. Example: console.log('Hello')
outputs 'Hello' in the console.document
to access and manipulate HTML content. Example: document.title = 'Hello JS'
changes the page title.window.open('URL')
opens a new browser window/tab with the specified URL.window.close()
closes the current browser window/tab.window.resizeTo(width, height)
resizes the browser window to given width and height.window.moveTo(x, y)
moves the browser window to the specified (x, y) screen coordinates.window.location
object contains details about the current URL, such as protocol, hostname, pathname, and search parameters.window.location.href = 'newURL'
changes the URL of the browser window.http
, https
), domain, TLD (Top-Level Domain), path, and query parameters.localStorage.setItem('key', 'value')
, sessionStorage.setItem('key', 'value')
to store data.localStorage.getItem('key')
, sessionStorage.getItem('key')
to fetch stored data.window.alert('message')
shows an alert box with the message. Blocks the browser until the user responds.window.confirm('message')
shows a confirmation box, returns true
or false
based on userโs choice.window.prompt('message', 'default value')
shows a prompt box to take user input.setTimeout(function, delay)
runs a function once after a specified delay (milliseconds).setInterval(function, delay)
repeatedly runs a function at the specified delay interval.clearTimeout(timeoutID)
clears a timeout set with setTimeout()
.clearInterval(intervalID)
clears an interval set with setInterval()
.window.location.reload()
reloads the current page.window.location.assign('URL')
loads a new document.window.location.replace('URL')
replaces the current document with the new one without saving the current page in session history.window.open('https://google.com', 'newwindow', 'width=400, height=400')
.window.history.back()
and window.history.forward()
navigate backward and forward in browser history.window.history.go(n)
where n
can be any integer to navigate by number of pages in history.window.scrollBy(x, y)
scrolls the document by specified x and y pixels.window.scrollTo(x, y)
scrolls the document to specified coordinates.element.scrollIntoView()
scrolls the document until the element is in view.setInterval()
for creating countdowns. Update text every second until reaching zero.localStorage
and retrieve them on subsequent visits.