In this section, I will be using persons as examples, like a person's name, age, or job. But anyway, let's talk about values now. A value is basically a piece of data, so it's the most fundamental unit of information that we have in programming.
"Naruto" is same as
'Naruto', but using
'Naruto' will give you an advantage and can be seen as we move forward in this course. So, for now, use this convention for writing any string.
We will use
console.log so frequently that you will get the hang of it in no time. Also, did you notice that I used a semicolon at the end of the line
period(".") in framing an English sentence.
What about integers?
How can a number be a string?
What does that even mean?
Let's have a closer look at these by introducing a simple Mathematical Operation, the addition.
Now, one extremely important thing that we can do with Values is to store them into Variables. And with this way, we can re-use them again and again.
let, which allows us to name the variable. Go through the below-mentioned code sample line by line for more information.
Here we have a box called a hero and into the box, we put the value of Naruto. And now if we want to use this value, all we have to do is to use this label or in other words this variable name; hero.
Now, let's combine our knowledge of string concatenation and variables and see what we can do.
Most of the time, we will declare a variable rather than just creating it; here is a classic example that uses both declaring and creating simultaneously.
One of the biggest advantages of using variables is its ability to be used at multiple places. How? For example, rather than manually changing a particular repeated value manually at multiple places, I can create a variable and assign it a value and place this variable, wherever I need this value. This way, whenever I reassign the variable, all the other places will be updated automatically.