Get Programming with JavaScript - Listing 3.03
Listing 3.03 - A book as an object
JS Bin
var book;
book = {
title : "The Hobbit",
author : "J. R. R. Tolkien",
published : 1937
};
console.log(book);
Further Adventures
Listing 3.03 - A book as an object - Task 1
- Change the title of book to "The Hobbit, or There and Back Again".
var book;
book = {
title : "The Hobbit, or There and Back Again", // update title
author : "J. R. R. Tolkien",
published : 1937
};
console.log(book);
Listing 3.03 - A book as an object - Task 2
- Try creating a book2 object.
var book;
var book2; // declare a new variable
book = {
title : "The Hobbit, or There and Back Again",
author : "J. R. R. Tolkien",
published : 1937
};
// assign a new book to the variable
book2 = {
title : "Northern Lights",
author : "Philip Pullman",
published : 1995
};
console.log(book);
Listing 3.03 - A book as an object - Task 3
- Log book2 to the console.
var book;
var book2;
book = {
title : "The Hobbit, or There and Back Again",
author : "J. R. R. Tolkien",
published : 1937
};
book2 = {
title : "Northern Lights",
author : "Philip Pullman",
published : 1995
};
console.log(book);
console.log(book2); // log the new book