What are the global objects available in Javascript and how to access their predefined constants and methods?

130 Views Asked by At

I am learning Javascript. While learning I come across the term 'Global Objects'.

Then, I come to know about one of the global object 'The Math object'.

I also come to know that, unlike other global objects, 'The Math Object' has no constructor. Its methods and properties are static. All of its methods and properties (constants) can be used without creating a Math object first.

So, someone please explain and let me know what are those all global objects available in Javascript and how to access their predefined constants and methods?

Also, explain me what is the exact need of these global objects?

Thank You.

1

There are 1 best solutions below

1
On

Global Objects means part of the Global Object. This will be window in browsers. All variables in the highest scope are automatically in that object:

var glob=true;//this is assigned to window
function test(){
   var glob=false;
}

console.log(window.glob);//we can test that
window.glob="test";//we could also directly write to that object.

Math is part of the window object, so you could do:

window.Math.abs(-10);

But as window and highest scope are equal, one can also do:

Math.abs(-10);//will be found in the highest scope

So Math is global as its in the global scope == global object.