4

I know that getBoundingClientRect() returns an object of type ClientRect or DOMRect, and each usually has properties like x, y, width, height, and more. And if you typeof those properties, you get Number.

So my question is, that Number is an amount of what? Pixels px, points pt, percentage %, and things like that are possible answers. I think it is pixels, but I am not completely sure about that. Could anyone confirm this?

Lakshya Raj
  • 1,669
  • 3
  • 10
  • 34

1 Answers1

2

Thank you to @Ken White for confirming the answer:

getBoundingClientRect() returns an array of Numbers that specify an amount of pixels (px).

Lakshya Raj
  • 1,669
  • 3
  • 10
  • 34
  • So why is the returned number a floating point..? – Redu Dec 20 '21 at 19:56
  • 1
    @Redu: The width of your element (in pixels) could be a floating point number. This is because although a 5px wide element wouldn't look any different from a 5.2px wide element, when you zoom in to 500%, you can see that one of them is 25px (on the screen) and the other is 26px. This is why it makes sense that numbers returned from `getBoundingClientRect()` are floating point numbers. The fraction of a pixel counts. – Lakshya Raj Dec 21 '21 at 02:18