lundi 28 décembre 2020

weird syntax Javascript [duplicate]

I saw this piece of code in a book :

let book = {
  subtitle : {
    title : "nothing",
    }
}
let len = undefined;

// the first one
if (book) { 
  if (book.subtitle) len = book.subtitle.length;
}

// the second one (which i have no idea what is)
len = book && book.subtitle && book.subtitle.length

can anyone explain how does the second done work?

Aucun commentaire:

Enregistrer un commentaire