10 Most Useful Things Of JavaScript
2 min readMay 5, 2021
- Variables:
JavaScript variables are containers for storing data values. There are 3 different types to store values. Like:
var, let, const - Array:
The most useful and needy part of any language to store and handle data in javascript. An array can hold many values under a single name. Create a simple array as like bellow:var array_name = [item1, item2, …];
- ‘==’ vs ‘===’ Operator:
‘==’ double equal to basically compare two values equality. That means this operator only depends on only value. Like:
`5`==5 //true
BUT
‘===’ triple equal to or strict equal operator compares booth value and type. Like
`5`==5 //false
as the two values are of different types. - Self-Calling Function:
This function automatically calls itself and completes its operations with arguments value. It might be an anonymous function also. As following:(function(x,y){
var sum= x+y;
return sum;
})(10,20) //output: 30 - Empty an Array:
let arr =[20,10,45]
arr.length=0 ; //
or,
arr = [] - Create Random Numbers:
var x = Math.floor(Math.random() * (max-min+1))+min ; - Useful Math Methods:
Math.abs(-6) //6 →return absolute value of any number or var
Math.round(25.69) //26 → return round value and add 1 if the value=>5
Math.ceil(6.75)//6 → return the nearest round value of downwards
Math.floor(6.75)//7 → return the nearest round value of upwards - Create Random Values:
var num=Math.round(Math.random()*10)
to extend the range of random values, change the multiplication value to 100, 1000, ……….
console.log(num) //return random value (0–10) - Convert into Integer:
parseInt(“anyValue”,base);parseInt(“10”,10)//return decimal value 10
parseInt(“11”,2)//return binary to integer 3 - Basic Tips:
* Don’t create string as object type if not needed because it slows down execution speed.
* Comparing objects type always return false.
*