Skip to content

Instantly share code, notes, and snippets.

@gpbaculio
Created April 29, 2017 20:44
Show Gist options
  • Save gpbaculio/d76022b1e0894507c0038b993cbd29db to your computer and use it in GitHub Desktop.
Save gpbaculio/d76022b1e0894507c0038b993cbd29db to your computer and use it in GitHub Desktop.
// alert requires only one argument, the 2nd and 3rd arguments are ignored and alerts only "Hello"
alert("Hello", "Good Evening", "How do you do?");
function power(base, exponent) {
if (exponent == undefined) {
debugger;
exponent = 2;
}
var result = 1;
for (var count = 0; count < exponent; count++) {
debugger;
result *= base;
}
return result;
}
console.log(power(4));
// passing only one argument will result exponent to have undefined value, so the if block condition is met, assigning 2 to exponent
// → 16
console.log(power(4, 3));
// → 64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment