The instructions for this exercise read:
* strings (e.g. "dogs go woof!")
* numbers (e.g. 4, 10)
* booleans (e.g. false, 5 > 4)
From the Mozilla JS data type doc I gather that "primitive data types" are one of six things (boolean, null, undefined, number, string, and symbol) which are "immutable", or can't be changed. These are in contrast to objects, which are not primitive because they can be changed. Would this be a correct understanding?
I can understand how this applies to most (don't know yet what the newest, "symbol", is), including numbers, sort of, but string is the most confusing to me, so I'm going to focus on that one. What does it mean that strings are immutable?
I've tried experimenting with it on my own (see below) and reading (ahem, trying to read) this stackexchange, but I'm not confident I understand what it means.
So for example, a variable can point to a string, and if I "change" that string (as per below for example), all I'm really changing is what string the variable is pointing to, and not the original string itself (which is presumably floating around somewhere in the ether out there)?
And if so, is every possible immutable string theoretically "in" every program to begin with, or are programs stringless until I start creating them?
var test = "hello " var test2 = "you" var test3 = test console.log(test += test2); console.log(test3);