Numbers

Get hands-on experience on how to use numbers as a JavaScript data type.

Context: JavaScript data types

When it comes to programming, pretty much everything we do revolves around storing and manipulating data. This data always has a type associated with it that tells the computer exactly how to handle the data that it’s given. In JavaScript, the data’s type is automatically determined when the code is executed.

What exactly do we mean by this? Let’s take a look at an example.

Press + to interact
var number1 = 10;
var number2 = 20;
console.log(number1 + number2);
1.

Pause and think: What do you expect this code to do?

Show Answer
Q1 / Q1
Did you find this helpful?

For your reference, console.log() outputs to the console whatever data is passed to it in between the parenthesis. You can run the code below to see the output.

Press + to interact
var number1 = 10;
var number2 = 20;
console.log(number1 + number2);

Numbers

Numbers are a numeric data type. Numbers can be integers, floating-point (numbers with a decimal), or exponential values like those you would find with scientific notation.

All numbers in JavaScript are stored using 64 bits of memory. While delving ...