Write-only variables !

Variables which cannot be read at the JS/interpreter level !

let myArray = [,,,,,"5","6"];
let myObject = { 5:"five",6:"six" }

let a := (5,"salt") // a == 5 !
a == 5 // ReferenceError: a is not defined !
(a) == 5 // false
(a + "salt") == 5 // false
a + 3 // 3
(a + "salt") + 3 // 3
myArray[a] // undefined
myObject[a] // undefined
myArray[(a + "salt")] // "5"
myObject[(a + "salt")] // "five"
console.log(`The value of a is ${ a } ${ (a + "salt") }`) // "The value of a is undefined undefined"

a := 6 // undefined
a := (6,"salt") // a == 6 !
a == 6 // ReferenceError: a is not defined !
myArray[a] // undefined
myObject[a] // undefined
myArray[(a + "salt")] // "6"
myObject[(a + "salt")] // "six"

let b = (a + "salt") // "salt"

it is unclear what you are doing,
The variables defined using "const" keyword are write only. Scope variables are pretty private, there are also Symbol and WeakMap for some "strange to me" use cases.
ReferenceError is typically thrown independently of the place of the identifier.

1 Like

It's really unclear what "write-only" means to you, what this would be good for, and how your := and + operators are supposed to work. Please post a description of the feature, not just some demo code.

Also,

(a + "salt") == 5 // false
// contrasted against
const myObject = { 5:"five",6:"six" };
myObject[(a + "salt")] // "five"

defies the laws of JavaScript regardless what (a + "salt") evaluates to.

1 Like

What can you do with a "write-only" variable if you never read it? In TypeScript this kind of variable (write, with no read) is treated as an unused variable.