Do primitive values have references?

Do primitive values have references?
0

#1

i m currently reading a book , and i m not quiet sure about this line , Do primitive values have references?


#2

Well a variable is reference to a value, primitive or not. But whenever you apply a method to a primitive, it coerces it to an object. So like

// a primitive
> let str = "Hello" 
 // coerce it to an object with the property `length`,
// and access that property
> str.length
5
// Immediately gets coerced back to a primitive
> str
"Hello"

You have to do some work to keep that object around (and in strict mode, you flat out can’t keep it around), and there is basically zero reason to need to. If you don’t try to keep hold of it, JavaScript will just prevent you accessing it: it’s hidden, an implementation detail.