It only applies to Arrays and Objects.
Strings, Numbers and Booleans can be changed locally without modifying the global.
Consider this code:
let myArray = [ 1, 2, 3 ]
This will create a new Array object in memory and myArray
will be a pointer to it in memory.
If you do operations that modify the contents of the array such as:
myArray[1] = 4
myArray.push(1)
then you are modifying the array held in memory.
But if you do:
let myArray = [ 1, 2, 3 ]
myArray = [ 2, 3, 4 ]
then you are creating a new array object in memory and changing what myArray
points to. This is a reassignment - it does not change the original array.
Now lets consider strings, numbers and booleans,
let myString = "foo"
Strings, numbers and booleans are called immutable types. They cannot be changed. Any operation you do on a variable of that type will reassign the variable to point to the new value. When you do something like:
myString = myString + " bar"
You are reassigning myString
to point to a different String value. The original string foo
has not been changed.
This all applies to working with context in Node-RED.
let timing = global.get("timing")
Is creating a locally scoped variable pointing to the value of the global context value.
If it is an Array or Object and you modify the contents of that object, you modify the value in context.
If it is a String, Number or Boolean and you change its value, you are reassigning what the local variable points at and the context value is untouched.