Get Programming with JavaScript - Listing 5.02

Listing 5.02 - Breaking a function by changing a variable name

var msg; var showMessage; msg = "It's full of stars!"; showMessage = function () { console.log(message); }; showMessage();

Further Adventures

Listing 5.02 - Breaking a function by changing a variable name - Task 1

var msg; var showMessage; msg = "It's full of stars!"; showMessage = function () { console.log(msg); // Use the correct variable }; showMessage();

Listing 5.02 - Breaking a function by changing a variable name - Tasks 2 & 3

var msg; var msg2; // Declare a variable var showMessage; msg = "It's full of stars!"; msg2 = "We choose to go."; // Assign a value showMessage = function () { console.log(msg); console.log(msg2); // Display the new message }; showMessage();

Listing 5.02 - Breaking a function by changing a variable name - Task 4

var msg; var msg2; var showMessage; msg = "It's full of stars!"; msg2 = "We choose to go."; showMessage = function () { console.log(msg + " " + msg2); // Display a single message }; showMessage();