0
Challenge · 14Just Enough JavaScript
Objects as records
JavaScriptused in ~85% of apps
An array numbers its boxes. Sometimes numbers are the wrong labels. You want to look something up by a name. That is an object, and it comes with one trap that quietly corrupts data.
Core idea. An object stores values under named keys instead of numbered positions. Looking up by name is instant. But every key is silently turned into text, which means the number 1 and the text "1" become the same key.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
an object holds named values
const student = {
name: "Priya",
score: 88,
passed: true,
};
student.name // "Priya"
student["score"] // 88
student.missing // undefinedevery key becomes text
const o = {};
o[1] = "number one";
o["1"] = "text one";
console.log(o);
// { "1": "text one" }
// ONE key, not two.
// The first value was overwritten.Verified by running it. The number key and the text key are the same drawer.
↑ play a little first, then dig in