I am trying to understand the structure of the javaScript language.
Can someone please tell me:
I understand that isNaN() is a method on the Number constructor.
So, how is it that the following two examples are able to work?
console.log(isNaN(3));
or
if(isNaN(3)) {
console.log(`3 is *not* a number`);
} else {
console.log(`3 is a number`);
}
There is no isNaN() function on the window --> i.e. window.isNaN() does not exist.
And you are not writing 3.isNaN() or Number.isNaN(3)
How is it that just writing the isNaN() function (or any other Number method) on its own, you are able to access the Number constructor?
For contrast:
When you implement a String method, you dot it off of an actual string, so the String methods are inherited by this string method. Example:
let littleString = 'I am a string'.toLowerCase();
You can't write:
toLowerCase('I am a little string');
or you will get an error:
ReferenceError: Can't find variable: toLowerCase
So, why can you do this with numbers?
Thanks!