I just started learning about Dart.
Before Dart, I have worked with Javascript and have some experience.
Now, as I was going through the documentation from Tutorial Point. They have mentioned something like this
All variables in dart store a reference to the value rather than containing the value. The variable called name contains a reference to a String object with a value of “Smith”.
In Javascript, I guess array and objects are reference type.
Meaning, If we do something like this
[Update:] This code snippet is incorrect
let a = ["Apple", "orange"]
let b = a
a = ["Bananna"]
console.log(b) //["Bananna"]
but that is probably only for object and array in JS (and not for const and let)
let a = 5
let b = a
a = 7
console.log(b) //5
From the quote,
All variables in dart store a reference to the value
[Question:] Does this mean that even things like int, string.. and every variable we create in Dart is reference? and the equivalence of above code will print 7 in Dart or I am getting something wrong (in general)?
let a = 5
let b = a
a = 7
console.log(b) //7
["Apple", "orange"]and then reassigning to["Banana"]is not how javascript behaves. In that case["Apple", "Orange"]would be logged to the console. - Nate Bosch