//
and multi-line comments between /*...*/
person
with as many properties-values as we want. You can access/modify the value of a specific property in two different ways:+
), subtraction (-
), multiplication (*
), etc.=
).x === y
, x < 5
, x > 20
...x < 5
&&
y > 25
"x" must be less than 5 AND "y" must be more than 25.==
and !=
operators exist, but they are never used because sometimes they don't behave properly (i.e. 0 == ""
is true!). For that reason everybody always uses three equals: ===
and !==
for comparisons.if-else
statement this way:else if
(each one with a condition) as you want, and it will run the code of the first one that matches true. Moreover, you can use if-else
without any else if
, or even without the else
statement, and it will continue with the rest of the code if condition1
is false.if-else
statements don't work. Instead, we have to use operators and ternary expressions. For more details, refer to React basics - Special cases.if-else
, and they let you run different code depending on a condition. This is the way to define them:i = 0
): The initial value when the loop starts.i < 5
): The condition that has to match to finish the loop.i += 1
): This is optional and is executed after each loop iteration. Usually used to change the value before running the next loop iteration.for loops
to run the same code for every array item. In these cases, we strongly recommend using the forEach() method instead.for loops
, while loops
perform the same code while a condition is true. You have to make sure that you change the condition in the code so you don't create infinite loops.do/while
which is a variant of the while loop
. The only difference is that it will execute the code block once, before checking if the condition is true, and continue while the condition is true
.var
; however, since ES6, it is not used at all. Instead, people use let
and const
:let
and var
too, and you can read about them here, but they are not that important and var
is not commonly used anymore.function
and adding =>
just after it.return
statement, you can change the curly braces { }
for parentheses ( )
, delete the return
statement, and it will return the whole function automatically.=
while defining the parameter.{ }
which equates them to the object properties you want to get the values from. Here you have an example of how to assign values with/without destructuring:person.name
and storing it in a variable called "a".[ ]
because we are working with arrays, and it will get values depending on the position.items
has just two elements, the first two variables are assigned values from the array while c
gets its default value.export
, and if you want to use anything external, you will use import
."./"
at the beginning. That way, JavaScript knows that it is a file. For example:"../"
.npm install
) you have to use the name of the package directly, without any "./"
before. Like this: