Table of Contents
1. Variables Definition in Node.js
2. Constants Definition in Node.js
3. Rule of naming variables and constants
1. Variables Definition in Node.js
Examples:
// use keyword: var
var a = “Nodejs Tutorial”
// not use keyword: var
b = “neoscorp.vn”
console.log(“Valiable a = ” + a)
console.log(“Valiable b = ” + b)
Ok, run: node unit3.js in terminal and see result:
Output:
Valiable a = Nodejs Tutorial
Valiable b = neoscorp.vn
2. Constants Definition in Node.js
Examples:
// constants difinition with data type is String
const c = “welcome to neoscorp.vn”;
// constants difinition with data type is Integer
const d = 10;
// constants definition with data type is Float
const e = 10.8;
// constants definition with data type is Logic(boolean)
const f = true;
console.log(“Constant c = ” + c);
console.log(“Constant d = ” + d);
console.log(“Constant e = ” + e);
console.log(“Constant f = ” + f);
Run: node unit3.js in terminal and see result:
Constant c = welcome to neoscorp.vn
Constant d = 10
Constant e = 10.8
Constant f = true
3. Rule of naming variables and constants
+ Variable and constant names must begin with a letter or an underscore character “_”.
+ Variable and Constant names are case-sensitive. For example, Name and name are two different variables.
+ Variable and constant names should not start with a numeral(0-9).
+ Name of variables and constants don’t contain speacial characters: !@#$%^&*()-
Note
Node.js is untyped language. This means that a Node.js variable can hold a value of any data type. Unlike nany other languages, you don’t have to tell Node.js during variable declaration what type of value the variable will hold. The value type of a variable can change during the execution of a program and Node.js takes care of it automatically.
Thank you!
You need to login in order to like this post: click here
YOU MIGHT ALSO LIKE