function functionWithArgs(a, b) {
console.log(a + b);
}
functionWithArgs(1, 2);
function functionWithArgs(a, b) {
console.log(a + b);
}
functionWithArgs(7, 9)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Passing Values to Functions with Arguments
Can you in non-strict mode? I sort assume strict as the default mode for writing JS? Accidental function redefinition is definitely the sort of bad behavior that should not be allowed.
SyntaxError: unknown: Identifier 'functionWithArgs' has already been declared. (6:10)
Really, I suppose you can re-define but not-redeclare in strict mode since a function is secretly a variable.
'use strict'
function functionWithArgs(a, b) {
console.log(a + b);
}
functionWithArgs(1, 2);
function functionWithArgs(a, b) {
console.log(a + b); // 3, 16
}
functionWithArgs(7, 9);
The function definition is overwritten. Then the function is hoisted so the first function call that comes before the second function definition still calls the second version of the function.
But I agree, it isn’t the behavior you really want. That is one benefit of using function expressions with let/const for your definitions, so you can’t redeclare them by accident.