Variables and data types Variables are containers that store data. When JavaScript code runs, these variables can be compared and manipulated. A variable can contain different types of data, and logical operations (see pp.270–71) should only be performed with variables of the same data type.
Primitive data types A primitive data type is a simple data value that is not an object or a method. There are three main primitive data types in JavaScript – numbers, Booleans, and strings. Data types do not need to be explicitly stated at the time of declaring a variable (see right); JavaScript automatically infers them from the code.
GOLD
$25 0
SILVER
$15 0
Numbers Unlike other programming languages, JavaScript does not distinguish between integers (whole numbers without a decimal) and floating point numbers (numbers with a decimal). All numbers in JavaScript are treated as floating point numbers.
Booleans Similar to Scratch and Python, Boolean variables in JavaScript also contain only two possible values – true or false. As the result of every logical operation is a Boolean value, these variables determine the flow of a program.
var isThisGold = true var price = 250; Number values do not have quotation marks around them
Boolean values do not have quotation marks around them