Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Introduction to Numbers | Numbers Booleans and Core Primitives
JavaScript Data Types Foundations

bookIntroduction to Numbers

Numbers are one of the most fundamental data types in JavaScript, representing numeric values that you use for a wide variety of everyday tasks. Whenever you need to store or process prices, scores, measurements, or any other kind of numeric information, you will use the number type. Whether you are calculating a total price in a shopping cart, tracking a player's score in a game, or measuring the distance traveled, numbers are essential.

12345678910111213
// Declaring number variables let price = 19.99; let score = 42; let distance = 3.5; // Performing simple arithmetic let totalCost = price * 3; // Multiplying price by quantity let newScore = score + 10; // Adding points to score let halfDistance = distance / 2; // Dividing distance by 2 console.log(totalCost); // 59.97 console.log(newScore); // 52 console.log(halfDistance); // 1.75
copy

In JavaScript, numbers can be either integers (whole numbers like 10, -3, or 0) or floating-point numbers (numbers with a decimal point like 3.14, -0.5, or 100.0). Both types are treated as the same number type in JavaScript, so you do not need to declare them differently. This makes working with numbers flexible, but it is important to be aware that floating-point numbers can sometimes behave unexpectedly in calculations due to how computers represent decimal values.

question mark

Which of the following is true about numbers in JavaScript?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 6.25

bookIntroduction to Numbers

Swipe to show menu

Numbers are one of the most fundamental data types in JavaScript, representing numeric values that you use for a wide variety of everyday tasks. Whenever you need to store or process prices, scores, measurements, or any other kind of numeric information, you will use the number type. Whether you are calculating a total price in a shopping cart, tracking a player's score in a game, or measuring the distance traveled, numbers are essential.

12345678910111213
// Declaring number variables let price = 19.99; let score = 42; let distance = 3.5; // Performing simple arithmetic let totalCost = price * 3; // Multiplying price by quantity let newScore = score + 10; // Adding points to score let halfDistance = distance / 2; // Dividing distance by 2 console.log(totalCost); // 59.97 console.log(newScore); // 52 console.log(halfDistance); // 1.75
copy

In JavaScript, numbers can be either integers (whole numbers like 10, -3, or 0) or floating-point numbers (numbers with a decimal point like 3.14, -0.5, or 100.0). Both types are treated as the same number type in JavaScript, so you do not need to declare them differently. This makes working with numbers flexible, but it is important to be aware that floating-point numbers can sometimes behave unexpectedly in calculations due to how computers represent decimal values.

question mark

Which of the following is true about numbers in JavaScript?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1
some-alt