"Looks For-In To Me" Dot vs Bracket notation


Why is it that when I wrote

  var langvalue = languages.lang;

The code does not work? I read somewhere that dot notation means literal value while bracket can read variable-- but I don't really understand what that means. What is literal value?

var languages = {
    english: "Hello!",
    french: "Bonjour!",
    notALanguage: 4,
    spanish: "Hola!"

// print hello in the 3 different languages
for(var lang in languages){
    var langvalue = languages[lang];
    if(typeof langvalue == "string"){


literal value in this case means english, french and so on. Literally the literal value of the object properties, look:


however, due to your for loop lang is a variable, so you need to use square brackets


So the literal value of English isn't "Hello?" What is it then?


english is the literal value. "Hello!" is the value associated with this literal value


You're probably referring to that these two expressions are equivalent:




This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.