JavaScript Basics
JavaScript Basics
JSBIN is an online platform to code and run it, so you can see in real time what you are creating
In JavaScript a string appears like: 'something in a string' but, numbers appear like: 23
Commands
Command Description Example
console.log(…) Comment processed by the
computer, it is an output, so it is It will be seen…
visualized
//… It is a comment that it is not
processed or evaluated by the
computer, so it is not visualized
Single Line Comment
/*…*/ It is a comment just like the
Single Line Comment but you
can just write as many lines as
you want, without having to
do // before every single one of
them (adequate when you want
to write a lot!)
Block Comment
let It is the way for the code to
identify that what follows may
be a variable (see chapter
Variable)
It is the way for a variable to be
declared
const This command is the command
to declare a variable that cannot
change its value along the code
Variable
A variable is just something that let us store a value
Example:
Let myfavoritenumber = 7
Console.log(myfavoritenumber)
On screen it will appear the number 7
Putting something equal (=) to other thing is called ASSIGNMENT, because you are associating
something to other thing, in this case, you are associating a variable to a value (see chapter
Declaration and Assigment).
However, the variable is not being processed, because it is not assigned to a value yet. So, if
we run the code, it will appear “undefined” because it is not associated to nothing.
In this case, the variable means something already, so when we print it, it will appear “-54”.
Possible error: If we make a mistake writing the variables name with the console.log()
command, we get an error like this:
Constants
Variables that cannot be changed are constants.
This means they can only have only 1 value ever, so if you try to give it another variable it will
originate an error, like this: