Languages
[Edit]
EN

Node.js - global variables

0 points
Created by:
p_agon
589

In this article, we would like to show you how to declare and use global variables in Node.js.

Quick solution:

 

Introduction

Edit

Global variables such as regular variables can be initialized with a value, changed, and even cleared out.

The only difference between a global variable and a regular variable is their scope.

Practical example

Edit

In this example, we create global variable inside example.js file. We can also use and modify it in index.js file.

index.js

example.js

Run the application :

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join