Strings are essentially a "static" series of characters of any kind, surrounded by either single quotes, or double quotes. They don't really have a size limit, but by default they got to be on a single line.
Strings look like this:
let myString = "I'm a string.";const otherString = 'This is also a string';// If you're using the double or single quotes they have to be "escaped":const escapedSingle = 'I\'m cool and it\'s fine!';const escapedDouble = "This is an \"escape\" from real life";// You can put strings together, called "concatenating" using a + sign:const concatString = escapedSingle + " I'm in the middle " + escapedDouble;// You can also append a string with the special += method:myString += " and I've added to myString now!";
There are more complex strings called Template Literals, used amongst other things for better string concatenation, but they deserve their own page so head on over there to learn more about them!
const myInt = 42; // note the lack of any quotes!const myFloat = 346.32462346;// You can do some math with JS, of course. The language follows regular math order// of operation, parentheses go first, then * and / , etc.const myResult = 10 * (33 - 5) / 2 + 8; // result: 148
0.1 + 0.2will actually not equal
A boolean is essentially a value that is true or false. Defining a boolean is essentially super easy:
const imTrue = true;const imFalse = false;
Now, that's not extremely useful to be honest, but booleans are much, much more than that. There are many operations that will return a boolean value when you execute them. Here are a few examples:
const isBigger = 5 > 2; // trueconst isEqual = "blue" === "red"; // false
Some things are not quite booleans but will act the same. I will reserve this explanation for conditions however, which are explored in another part of this guide. That's also where we'll talk about those operators I just used!
Some values can be either null or undefined, so these two types are considered data types, but are generally used under very specific circumstances.
let test; // test is "undefined" but won't crash the botconsole.log(test); // undefinedconsole.log(x); // crashes with "ReferenceError: x is not defined;const what = null; // validconsole.log(what); // null