Some Javascript fundamentals

Shabnam Priyanka
2 min readNov 2, 2020

--

  • Push lets you insert a name or number at the end of an array. For example, if you declare an array with a bunch of names and you want to add more names but at the end of the list then you have to use the Javascript push method.
  • Pop lets you remove an item from the end of the list of an array. For example, if you want to remove a name or number from the end of an array then you have to use pop method.
  • Length tells the position of an array. For example, if you have 10 names or numbers, by using the length method you can find out which name or number is in which position.
  • Shift lets you remove the item from the beginning of an array. For example, you have created a big list of numbers in an array. But you want to remove some numbers from the beginning then you have to use the shift method.
  • Unshift is the opposite of the shift method. For example, if you want to add a name or number at the beginning then you have to use the unshift method.
  • Math.ceil method will take the number and give you the highest number. Suppose if you put 5.56 then it will return 6 as the answer. For example number = 5.894; var num = Math.ceil(number); console.log(num);

The answer will be 6.

  • Math.floor method will give you the lowest number. For example, var number = 5.894; var num = Math.floor(number); console.log(num);

The answer will be 5.

  • Math.round this method rounds up to the closest number. For example, var number = 5.894; var num = Math.round(number); console.log(num);

The answer will be 6.

  • parseInt will remove the number after the integer. If you are sure about the number then use it otherwise don’t use it. For example, var number = 15.5 if you use parseInt function then .5 will be removed. var number1 = 25; Var number2 = ‘15.46’; Number2 = parseInt(number2);

console.log(number1 + number2);

The answer will be 40.

  • parseFloat will change string to a number. For example, var number1 = 25; Var number2 = ‘15.46’; Number2 = parseFloat(number2);

console.log(number1 + number2);

The answer will be 40.46. But if you don’t convert the string to a number then it won’t add up like this. The answer will be 2515.45 if you don’t use parseFloat.

--

--