🍫Numbers

In JavaScript, a number is a numeric data type that can be an integer (e.g. 1, 2, 3) or a floating-point number (e.g. 1.5, 3.14, 5.0).

You can convert a number to a string by using the toString() method:

let num = 123;
let str = num.toString();
console.log(typeof str); // Outputs "string"

You can also use the String() function to convert a number to a string:

let num = 123;
let str = String(num);
console.log(typeof str); // Outputs "string"

If you try to perform an operation that is not allowed for numbers (e.g. dividing a string by a number), the result will be NaN, which stands for "Not a Number".

For example:

let num = 'foo';
let result = num / 2;
console.log(result); // Outputs NaN

Let's look at an example of Numbers in the context of a Sports games

Last updated