Substitution in JavaScript

Hi. I’ve learned how to use a variable that looks like this:

var x = 3;

I also know how to replace a string with another using String.replace(). That should looks like this:

console.log("Hello world".replace('Hello', 'Hi')); //Hi world

But I have a question.

Let’s consider that we substitute x = 5 and y = 5 + 5. The given code should look like this:

let x = 5;
var y = x + 5; //y is 10
console.log(y); //return 10

The given code above is the same as:

let x = 5;
var y = 5 + 5; //y is 10
console.log(5 + 5); //returns 10

And yeah. What is substitution in JavaScript? And how does it works??

Please answer.

Thanks!
@pummarinbest

Here the value of x variable is substituted where x is being used i.e. line 2. x is a container that stores/holds some data.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.