Numbers
Part of the Fundamentals section of Coddy's JavaScript journey — lesson 5 of 77.
Variables are containers that hold data values. They are used to store, manipulate, and display information within a program.
In short, a variable is like a memory unit that we can access by typing the name of the variable.
Each variable has a unique name and a value that can be of different types. JavaScript is capable of automatically detecting the variable type, which makes coding more efficient.
To initialize a variable, we use the following format:
let variable_name = valueLet's take a look at the different types of numbers:
JavaScript has a number type that can represent both integers and floating-point numbers.
number - can be a whole number, such as 1 or -2, or a real number, such as 1.32 or 0.98.
For example:
To initialize a variable of type number with the name a and the value 3:
let a = 3To initialize a variable of type number with the name b and the value 13.2:
let b = 13.2Challenge
BeginnerWrite code that initializes a variable named c with the value 5.
Cheat sheet
Variables are containers that hold data values. To initialize a variable, use the let keyword:
let variable_name = valueJavaScript has a number type that can represent both integers and floating-point numbers:
let a = 3 // integer
let b = 13.2 // floating-pointTry it yourself
// Type your code below
let c = ?
// Don't change the line below
console.log(`c = ${c}`)This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False