10 Most Useful Things Of JavaScript

NURUL MOSTAFA RAHAT
2 min readMay 5, 2021
  1. Variables:
    JavaScript variables are containers for storing data values. There are 3 different types to store values. Like:
    var, let, const
  2. 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, …];
  3. ‘==’ 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.
  4. 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
  5. Empty an Array:
    let arr =[20,10,45]
    arr.length=0 ; //
    or,
    arr = []
  6. Create Random Numbers:
    var x = Math.floor(Math.random() * (max-min+1))+min ;
  7. 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
  8. Create Random Values:
    var num=Math.round(Math.random()*10)
    console.log(num) //return random value (0–10)
    to extend the range of random values, change the multiplication value to 100, 1000, ……….
  9. Convert into Integer:
    parseInt(“anyValue”,base);
    parseInt(“10”,10)//return decimal value 10
    parseInt(“11”,2)//return binary to integer 3
  10. Basic Tips:
    * Don’t create string as object type if not needed because it slows down execution speed.
    * Comparing objects type always return false.
    *

--

--