Install nodejs
Download nodejs LTS version from here
After installing it, open CMD and check nodejs version by following command:node --version
If showing version, then nodejs has been installed successfully

Install IDE
We will install Visual Studio Code as IDE because this is very light, more friendly and support most of the plugins for nice development experience.
Download VSC from here
While install, check all of the check-boxes
First Program
Create a new folder. Give it any name
open the blank folder with visual studio
Open the terminal. Go to Terminal > New Terminal
Hit the following command:
npm init -y
package.json will be generated
create a new flle name hello.js
Write following code:
console.log('Hello world')
Now hit following command to run the program:node hello.js
Output: Hello world
Variable
Variables are used for storing data.
For example, var name=”Hasan”; var number=10;
Here, name and number are variable
Using let and const (ES6)
Before 2015, using the var
keyword was the only way to declare a JavaScript variable.
JavaScript (ES6) allows the use of the const
keyword to define a variable that cannot be reassigned, and the let
keyword to define a variable with restricted scope.
Variable writing rules
- All variable names must begin with a letter of the alphabet or an. underscore( _ )
For example: myVariable, _number - One phrase variable should be small and two phrase variable name should be camelCase
- One phrase variable example: name
Two phrases variable example: firstName - Variable name should not be start with number.
For example:2usernamecan not be used - After the first initial letter, variable name can also contain letters and numbers.
For example: userName1, userName2 - Uppercase characters are different from lowercase characters.
For example: a and A are different variables - You cannot use JavaScript reserved keywords as a variable name. For example:
let. var, constetc - Space or special characters are not allowed in variables.
For example:first name, first#name, first@name
User Input
install this package:
nmm i prompt-sync
write following code:
const prompt=require('prompt-sync')();
let name=prompt('Enter your name: ')
console.log(name);
Hit following command:
node hello.js
Output: Enter your name: Salman
Salman
Commenting
Use // to comment a line or multiple line
const prompt=require('prompt-sync')();
//input your name
let name=prompt('Enter your name: ')
console.log(name);
Identifiers (let, var, const)
let and const both used in JS es6 version
let: used in local scope (also you can use it globally)
var: used in global scope (also you can use it locally)
const: used only for assigning constant variables. Constant means the variable value will not be changed or assigned.
Datatypes
There are 6 types of datatype in JavaScript
- Number
- String
- Boolean
- BigInt
- Symbol
- Undefined
For example,
var number= 10; // Number
var name= “Salman”; // String
var obj = {firstName:”Salman”, lastName:”Srabon”}; // Object
Checking Datatypes
let name="Rahim";
console.log(typeof(name))
Output: string
let value=1.5;
console.log(typeof(value))
Output: number
let bool=true;
console.log(typeof(bool))
Output: boolean
Parsing Datatypes
To convert integer type digits to string:
value.toString();
Or
String(value);
To convert string type digits to integer:
parseInt(value);
To convert string type digits to float:
parseFloat(value);
To convert float type to integer:
Math.floor(value);
Math.ceil(value);
Math.round(value);
Math.trunc(value);
To fix the decimal value:
value.toFixed(number);
To precise the decimal value:
value.toPrecision(number);
String concat
“+” plus operator will be used to concat two or multiple variables.
Example:
let firstName="Shakib";
let lastName="Khan";
console.log(firstName+" "+lastName)
Or,
`${}` sign will be used to concat variables values in a string.
Example:
let firstName="Shakib";
let lastName="Khan";
console.log(`${firstName} ${lastName}`)
JS Operators
There are 6 types of operators
- Assignment operators
- Comparison operators
- Logical operators
- Type operators
- Bitwise operators
- Arithmetic operators
Assignment Operators
Operator | Example |
= | x = y |
+= | x += y |
-= | x -= y |
*= | x *= y |
/= | x /= y |
%= | x %= y |
**= | x **= y |
Comparison Operators
Operator | Description |
== | equal to |
=== | equal value and equal type |
!= | not equal |
!== | not equal value or not equal type |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
Logical Operators
Operator | Description |
&& | logical and |
|| | logical or |
! | logical not |
Type operators
Operator | Description |
typeOf() | Returns the type of a variable |
instanceOf() | Returns true if an object is an instance of an object type |
Bitwise Operators
Operator | Description | Example | Same as | Result | Decimal |
& | AND | 5 & 1 | 0101 & 0001 | 1 | 1 |
| | OR | 5 | 1 | 0101 | 0001 | 101 | 5 |
~ | NOT | ~ 5 | ~0101 | 1010 | 10 |
^ | XOR | 5 ^ 1 | 0101 ^ 0001 | 100 | 4 |
<< | Zero fill left shift | 5 << 1 | 0101 << 1 | 1010 | 10 |
>> | Signed right shift | 5 >> 1 | 0101 >> 1 | 10 | 2 |
>>> | Zero fill right shift | 5 >>> 1 | 0101 >>> 1 | 10 | 2 |
Arithmetic Operators
Operator | Description | Example | Same as | Result | Decimal |
& | AND | 5 & 1 | 0101 & 0001 | 1 | 1 |
| | OR | 5 | 1 | 0101 | 0001 | 101 | 5 |
~ | NOT | ~ 5 | ~0101 | 1010 | 10 |
^ | XOR | 5 ^ 1 | 0101 ^ 0001 | 100 | 4 |
<< | Zero fill left shift | 5 << 1 | 0101 << 1 | 1010 | 10 |
>> | Signed right shift | 5 >> 1 | 0101 >> 1 | 10 | 2 |
>>> | Zero fill right shift | 5 >>> 1 | 0101 >>> 1 | 10 | 2 |
Necessary Math Functions
Getting absolute value: Math.abs(value);
Getting power of a number:Math.pow(value,power);
Getting square root of a number:Math.sqrt(value);
Getting random number: Math.random()
Getting max/min from numbers: Math.max(n1,n2,n3,,,,,,,,n);
Math.min(n1,n2,n3,,,,,,,,,n);
Leave a Reply