The code creates two variables, an object (n
) and a string (a
). The object's properties can be accessed with the .
or []
operator. You should read a description of how Javascript objects work, such as this one.
n.a // Accesses the 'a' property of n, which currently holds 1
n[ 'a' ] // Also accesses the 'a' property. Same as above.
n[ a ] // Since a holds the string 'b', the accesses the
// 'b' property of n
n.a == n.b // Compares n's 'a' property to n's 'b' property
n.a === n.b // Same, but does a strict comparison so type
// and value are compared
n.b == n.d // Another comparison with different properties
n.a =n= n.d // Sets n to true. Will cause the lines after this
// not to function as expected since n is no longer
// an object. See Barmar's comments below.
n.c ? "a" : "b" // Shorthand for if (n.c) return "a" else return "b"
n.e // Accesses 'e' attribute of n (Currently not set)
n.e != null // Compares (unset) e attribute to null