DEV Community

Bhupesh Chandra Joshi
Bhupesh Chandra Joshi

Posted on

What are the advantages of Global and Global this:?

Global is the javascript keyword introduced when javascript was commenced.

These Global objects are present in all modules in javascript on backend(you can call them node js modules), we are discussing the backend , some of the objects which you are utilizing and experimenting on your coding, they arrived from node js.

__dirname
You may be aware of this global variable, I don't this object this, we chat on instagram, facebook and the global means elders who can have access of your social media, same way this variale knows about your directory where you are executing your tasks.

*__filename *
When we engaged in refactoring any project, we need to adopt the speed, in comparative mananage, if you console.log(__filename), you will understand,what was the difference from previous command on blog.


exports-
We are fan of this varible who is our best friend when we performed the named export of our code. This is a OBJECT WHOSE INTITIAL VALUE IS EMPTY.

When you address the type of export , you will get console error and it is excelent may to maintain code functions and data into module,and then you will realize about the importance of this code,when you import your code in your project.
console.log(typeof export)

module-
Module is an object, because everything is object in javaScript, If you call ecma script developers,what they discuss about module, we dicussed about import and export, you know that import and exports are the module, we module our code in bundle,so that wood packet, we will be reuse, as require.

require()-
it is an older way to import the node modules from the node js and it's common js way to import.

It provides you the all the code files which require consist of, but if you are be aware of import keyword, you also grab the necessary code for your projects.

Global This:
When you know the history of global this, the access to this object changed, now it's updated to arrived in ECMAScript 2020 , a single and easy way to access the golab object.

The modern way is quite simplified in es2020:

Top comments (0)