Example 1 — Basic Read
Beginner example for window.scrollY.
console.log(typeof window.scrollY);
console.log(window.scrollY === window.pageYOffset); How It Works
- Step. scrollY aliases pageYOffset.

window.scrollY is how many CSS pixels the document is scrolled vertically. pageYOffset is the same value.
Read window.scrollY with no parentheses.
window.scrollY; | Call | What it does |
|---|---|
window.scrollY | Vertical scroll offset in pixels. |
Window property in browsers. No import required.
| Parameter | Description |
|---|---|
| window.scrollY | Read-only or assignable depending on the property. No function arguments. |
| Return Value | Description |
|---|---|
| * | Vertical scroll offset in pixels. |
Beginner example for window.scrollY.
console.log(typeof window.scrollY);
console.log(window.scrollY === window.pageYOffset); Beginner example for window.scrollY.
console.log(window.scrollY >= 0); Beginner example for window.scrollY.
const nearTop = window.scrollY < 40;
console.log(nearTop); window.scrollY is a standard Window property in browsers.
Available in all modern browsers. Not used in plain Node.js without a DOM.
Bottom line: Safe in browsers. Skip in server-only Node scripts.
Continue through the Window properties list.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
9 people found this page helpful