Objects
An object groups related values under named keys: { title: "Dune", year: 1965 } instead of three separate loose variables. You read a property back with
dot notation - book.title - and it reads almost like English.
Template literals (backticks instead of quotes) let you drop a variable or
expression straight into a string with ${...}, instead of gluing pieces
together with +. Combine the two and you can build a display string directly
out of an object's properties, so it stays correct even if the object's values
change later.
Your task: create an object book with title ("Dune"), author
("Frank Herbert"), and year (1965). Then build summary, a string reading
"Dune by Frank Herbert (1965)", out of those properties.
You'll practice:
Creating an object literal
Reading properties with dot notation
Building a string with a template literal
Show a hint
Show solution
Previous Next