Serenity Operating System
at hosted 27 lines 797 B view raw
1try { 2 var o = { 1: 23, foo: "bar", "hello": "friends" }; 3 assert(o[1] === 23); 4 assert(o["1"] === 23); 5 assert(o.foo === "bar"); 6 assert(o["foo"] === "bar"); 7 assert(o.hello === "friends"); 8 assert(o["hello"] === "friends"); 9 o.baz = "test"; 10 assert(o.baz === "test"); 11 assert(o["baz"] === "test"); 12 o[10] = "123"; 13 assert(o[10] === "123"); 14 assert(o["10"] === "123"); 15 o[-1] = "hello friends"; 16 assert(o[-1] === "hello friends"); 17 assert(o["-1"] === "hello friends"); 18 19 var math = { 3.14: "pi" }; 20 assert(math["3.14"] === "pi"); 21 // Note : this test doesn't pass yet due to floating-point literals being coerced to i32 on access 22 // assert(math[3.14] === "pi"); 23 24 console.log("PASS"); 25} catch (e) { 26 console.log("FAIL: " + e); 27}