Code Lab

Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar

Object keys and indexes

FácilBasics5 min

What does this program print? Write the output: one line for each console log call, in the same order.

const answers = { true: 'yes', 1: 'no', 1.0: 'maybe' };
console.log(answers);
console.log(Object.keys(answers).length);
console.log(['123', 'yes'][0][1]);
console.log(['123', 'yes'][false]);
  • Think about what each key of the object becomes. JavaScript changes values to other types by itself (type coercion).
  • In the last two lines, look at what each index picks.
  • Type each line exactly as the console shows it. An object is printed like { a: 1 }, with spaces inside the braces, and a string inside an object has single quotes. A key that is a valid variable name has no quotes; any other key, for example one that starts with a digit, is printed in single quotes.

Cobrada em Rostelecom · Fonte

Sua resposta
Carregando o editor...
Execute seu código para ver o resultado dos testes aqui