Dealing with numbers in javascript

Numbers in JavaScript the Basics


What does this mean? All JavaScript numbers are stored as double floating point numbers. JS will trick you into thinking that your const is an integer, but really it’s a float and equal to x = 5.0

test youself !!!

5 == 5.0
true


Math Object

JavaScript has a built-in Math object that provides a range of mathematical methods and properties. The most useful methods are:

Math.ceil : rounds a number upwards, so Math.ceil(8.23) returns 9

Math.floor : rounds a number downwards, so Math.floor(23.8) returns 23

Math.round : rounds the number to the nearest integer, so 

Math.round(8.3) returns 8, while Math.round(2.8) returns 3

Math.pow : raises one number to the power of another so Math.pow(2,3) returns


Testyourself:

Math.ceil(28.8)
29
Math.floor(28.8)
28
Math.floor(28.8)
28
Math.round(25.7)
26



Comments

Popular posts from this blog

JavaScript — Double Equals vs. Triple Equals - weird things on JavaScript

06_Understanding Execution Context and Execution Stack in Javascript

Creating and inserting element- part-2