= number_1 + number_2; function foo() { alert('This will never alert.'); } alert(sum); // only sum will be alerted // the string inside foo function does // not because foo was never called the code inside functions only executes when the function is called Thursday, October 1, 2009
name(name) { return 'The name was: ' + name; } // call the function var message = name('Ron Burgandy'); // message variable is now 'The name was: Ron Burgandy' // call the function again with different name message = name('Veronica Corningstone'); // message variable is now 'The name was: Veronica Corningstone' Thursday, October 1, 2009
name(name) { return 'The name was: ' + name; } // call the function var message = name('Ron Burgandy'); // message variable is now 'The name was: Ron Burgandy' // call the function again with different name message = name('Veronica Corningstone'); // message variable is now 'The name was: Veronica Corningstone' name is a parameter Thursday, October 1, 2009
name(name) { return 'The name was: ' + name; } // call the function var message = name('Ron Burgandy'); // message variable is now 'The name was: Ron Burgandy' // call the function again with different name message = name('Veronica Corningstone'); // message variable is now 'The name was: Veronica Corningstone' name is a parameter ‘Ron Burgandy’ is an argument ‘Veronica Corningstone’ is an argument Thursday, October 1, 2009
fullName(first_name, last_name) { return first_name + ' ' + last_name; } var wes = fullName('Wes', 'Mantooth'); // wes variable is now 'Wes Mantooth' var brian = fullName('Brian', 'Fantana'); // brian variable is now 'Brian Fantana' Thursday, October 1, 2009
{ alert('DO NOT WANT!'); } else { for (var i=0; i < loops; i++) { alert("Why'd you have to wait..."); } } } // alert DO NOT WANT! demoWithLoop(11); // 4 alerts of Why'd you have to wait... demoWithLoop(4); Thursday, October 1, 2009
10) { alert('DO NOT WANT!'); return; } for (var i=0; i < loops; i++) { alert("Why'd you have to wait..."); } } // alert DO NOT WANT! demoWithLoop(11); // 4 alerts of Why'd you have to wait... demoWithLoop(4); Thursday, October 1, 2009