JavaScript Browser Object Model - Exercise 1

It represents the browser window and provides access to browser-level features.

javascript

console.log(window.innerWidth);

Use window.location.href or location.href.

javascript

const currentUrl = window.location.href;

It navigates the browser to a new URL and keeps the current page in history.

javascript

location.assign('/tutorials/');

Call location.reload().

javascript

button.addEventListener('click', () => {
  location.reload();
});

It navigates to the previous page in the browser history.

javascript

history.back();

Use setTimeout with a callback and a delay in milliseconds.

javascript

setTimeout(() => {
  console.log('Later');
}, 1000);

Store the interval ID and pass it to clearInterval.

javascript

const id = setInterval(updateClock, 1000);
clearInterval(id);

It reports the browser's preferred language.

javascript

console.log(navigator.language);

It describes the width of the user's screen in pixels.

javascript

console.log(screen.width);

Different browsers or environments may not support every API.

javascript

if ('geolocation' in navigator) {
  console.log('Location is available');
}