In programming languages you'll always be working with different types of data. For example you could want to do some calculations with numbers or manipulate text in some way.
Integers are numerical values.
let visitorCount = 837; const PI = 3.141; let year = 2018;
I hope I don't need to explain why integers are important or when you'd need to use them, as it should be pretty obvious.
At this point this is not really important but you should never forget it.
Strings represent text.
const website = 'JS Bible'; const author = 'Rodrigo'; const url = 'https://jsbible.com'; const info = 'Share the site with your friends!';
A boolean is one of the simplest data types there are. They represent a logical value which can either be true or false.
Every day examples which you could store in a boolean could be things like:
- Is the light turned on?
- Is it raining outside?
- Is the earth flat..?
let userIsLoggedIn = false; let userIsPremium = false; let jsIsCool = true; // Using ! as a boolean operator console.log(userIsLoggedIn) // false console.log(!userIsLoggedIn) // true console.log(!!userIsLoggedIn) // false
You'll need booleans to do specific actions depending on specific conditions.
Let's say you have the same login interface of the strings section above. When a user sends a login request you might want to check if there was actually a value inserted in the e-mail and the password fields and only send the request to your server if there was.
It would make no sense to send the request with empty data, right?
There is no type identifier for a variable as in other programming languages. A good example would be Java.
// Store an integer inside the variable let number = 1; // Store a string inside the variable number = 'number';