(bright upbeat music)
- [Morten] The data we store and use in variables
and JavaScript falls into six primitive data types.
Three, we use all the time Numeric, String and Boolean
One We use occasionally null, one fallback, undefined
and a new one introduced in ECMAScript 2015 called Symbol.
The Numeric Data type handles numbers to
store a numeric data type and a variable simply
assign a number to it, it can be any regular numbers.
So 1, 2, 3, 56, 3,847, it can be an integer.
So 3.1492, et cetera it can be any negative number
or Integer, so minus one or minus 10
or minus 56.39 or minus 100 billion.
Now, technically there is a limit
to how big the number can be, but it's ridiculously high.
So for all intents and purposes, whatever number you put
in a variable will work as a numeric data type.
The String Data type handles strings of letters and symbols.
What we commonly refer to as words
and sentences to store a string data type
in a variable wrap your string
of texts in straight quotation marks
you can use single or double quotes
just make sure you use the same one at the beginning
and at the end, you can place any symbol
between these quotation marks, but when you use hyphens
or quotes in your text, you have to be extra careful.
If you use straight double quotes to denote the beginning
and end of the string, and then use straight
double quotes in the string as well.
Everything breaks because you're
terminating the string early to fix this.
You could use single straight quotes
for the string and double quotes inside
but that would just trigger the same problem with
apostrophes to resolve this problem properly
escaped the string quotes by placing
a backslash in front of each of them.
This tells the browser, this straight quote
is not part of the script treat it like regular text
and everything will be just fine.
The Boolean Data type handles the binary true/false to
store a Boolean Data type in the variable type
in true or false without quotation marks.
These are JavaScript commands and will be understood
by the browser, the same goes for the null Data type.
The null Data type is the intentional absence
of an object value, so if we want a variable
to be empty, but not undefined
you set its value to null without quotation marks as well.
The undefined Data type is what you get when
you create a variable, but don't set it to anything.
JavaScript is a weekly type language.
So the data types are applied.
When you set the content in a variable.
If you ever want to know what data type a variable has
you can use the typeof operator to find out.
If you open the browser, open the console
and type in console log, and then type
of followed by the variable name, you'll get the data type
for the content within that variable.
So we can say negInteger this returns a number
Or you can say escQuote, this returns a string.
We can say the sun is warm
That's a Boolean, empty inside that registers as an object.
That is an error in the browser itself.
That is the null value, but it's treated
like an object because the browser doesn't understand
because there's literally nothing there.
And finally, just another variable
which was undefined is undefined.
(bright upbeat music)