JavaScript Browser Object Model - Exercise 1
It represents the browser window and provides access to browser-level features.
console.log(window.innerWidth);
Use window.location.href or location.href.
const currentUrl = window.location.href;
It navigates the browser to a new URL and keeps the current page in history.
location.assign('/tutorials/');
Call location.reload().
button.addEventListener('click', () => {
location.reload();
});
It navigates to the previous page in the browser history.
history.back();
Use setTimeout with a callback and a delay in milliseconds.
setTimeout(() => {
console.log('Later');
}, 1000);
Store the interval ID and pass it to clearInterval.
const id = setInterval(updateClock, 1000);
clearInterval(id);
It reports the browser's preferred language.
console.log(navigator.language);
It describes the width of the user's screen in pixels.
console.log(screen.width);
Different browsers or environments may not support every API.
if ('geolocation' in navigator) {
console.log('Location is available');
}