Data Types
String
You've just learned how to call console.log()
to display some text. The message inside the parenthesis is a string:
'Hello, Buzz Coders!'
String is one of the basic data types in JS. They can be enclosed in either single or double quotation marks.
More string examples:
"I can write code"
is a string in double quotes'JavaScript is fun!'
another string in single quotes.
Single or double quotes are essentially the same, just make sure the quotation marks at the beginning and end of the string match.
Number
Another basic data type is number
type, including both integer and floating point numbers.
8
is an integer number105.88
is a floating point number-75
is a negative number
There are no quotation marks around numbers.
Try it! Print out an integer using console.log()
function, like so:
console.log(28);
Simple math
We all know computers are good at math. Here is how we can use JavaScript to calculate numbers:
console.log(3 + 15);
console.log(3 * 8);
console.log(10 - 2);
console.log(25 / 5);
Console results:
18
24
8
5