function expressions with function, with any number of arguments
var dbl = function(x) { x + x; }; var prod = function(x, y) { x * y; };
var dbl = function(x) { x + x; };
var prod = function(x, y) { x * y; };
function application, with any expression as a valid argument
var dbl = function(x) { x + x; }; var prod = function(x, y) { x * y; }; dbl(42); // 84 dbl(42 - 40); // 4 prod(42, 50); // 2100
var dbl = function(x) { x + x; };
var prod = function(x, y) { x * y; };
dbl(42); // 84
dbl(42 - 40); // 4
prod(42, 50); // 2100
Hint: Function expressions and function application also require handling of statement blocks between curly braces.
Upgrade + to handle string concatenation. Numbers “added” to strings should be converted to a string representation. Exact integers should not have a trailing .0.
var a = 24.5; var b = "foo"; a + a + b; // 49foo a + b + a; // 24.5foo24.5
var a = 24.5;
var b = "foo";
a + a + b; // 49foo
a + b + a; // 24.5foo24.5
alert function that prints its arguments as text with an ALERT! prefix.