Changing Powershell variable value not reflecting during echo

Hi, I’m stuck on a variable question.

Q:- Create two variables in PowerShell, one with the value of John and one with the value of Miller.

My Ans:- $firstname =“John”

$secondname =“Miller”

Create a third variable in PowerShell that will contain the two variables you just created, so that it returns John Miller

My Ans:- $fullname ="$firstname $secondname"

Now comes the confusing part.

Q:- If you change the first or second variable, the third variable should automatically change?

But When I changing the value of either first name or second name, the value of full name is not changing automatically.

I am attaching the screenshot. https://prnt.sc/s8dbx2

No it definitely won’t affect it. They are not references, you are taking the values of $firstname and $secondname and putting them into an unrelated variable.

Hi,

Referencing your codes:

$firstname = "John" $Secondname = "Miller" $fullname = "$firstname $Secondname" # you assigned/changed the variable $fullname # output: John Miller $firstname = "james" # this changed the $firstname variable $fullname # output: John Miller because the variable $fullname was not changed`</div> <div>`to get the desired result, you must update the $fullname variable $fullname = "$firstname $Secondname" $fullname # output: james Miller