Skip to content

“Assigning to and through literals and undefined” is not WTF #24

@cD1rtX3

Description

@cD1rtX3
'abc'[1] = 'B' // this does NOT modify the 'abc' string literal (so far so good) but returns 'B'
let B = 'abc'[1] = 'B' // so this does actually assign 'B' to B"
undefined = 'B' // this does not change undefined (so far so good) but also returns 'B'
let B = undefined = 'B' // so this does actually assign 'B' to B", through undefined

The = operator returns the right-hand side. let B = undefined = 'B' is not assigning undefined to B, it is assigning the rightmost-hand side of the assignment to both.

The real issue is that assigning to undefined etc. isn't a TypeError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions