Data Types
JavaScript has seven different data types, we're going to look at five of them now, and we'll look at one more later in JavaScript 201. You might already be familiar with the following concepts, don't let a term like "data type" scare you away, that's just what they're called to programmers.
Numbers
Numbers play a big part in JavaScript. We can do all normal math equations within JavaScript expressions, and you can test it out in the console of your browser, or by making a console.log(1 + 2);
statement in any .js
file that you have
Strings
Strings are any text inside of quotation marks, both double ""
or single ''
. A string can contain letters, numbers, symbols or any combination of the three!
It's important to understand the difference between
123
and"123"
, as they are not the same data type. You can do math on a number, but you can't do math on a String.
While we can't "do math" on a String, we can concatenate two Strings together. What does that mean? Well, we can use the +
sign to combine two Strings into one. Look at these examples, and notice how spaces must be included in our Strings if we want them to be part of a sentence:
Booleans
Booleans are a fancy way for saying "checking whether something is true or false". A boolean can either be true or false, and we can use booleans to design our programs, for instance - do Thing1 if this is true, and do Thing2 is this is false. Booleans will become important when we get into conditionals and looping in a few pages, but for now, just know that every expression in your JavaScript program is either true or false.
Undefined + Null
Something is undefined
if it hasn't yet been assigned a value yet. This will become more relevant once we talk about variables on the next page.
Null on the other hand is the intentional absence of a value. If something doesn't exist, than it is called null