+ 2

Two function with same name having different output on the same page. Which one will take precedence in js

function a(){alert(1);} function a(){alert(2);}

16th Dec 2016, 9:54 PM
nitin kalasi
2 Antworten
+ 3
The last one. In this case, it'll alert 2. When you declare 2 functions with the same name, the last one will overwrite the preceeding one.
16th Dec 2016, 10:14 PM
CHMD
CHMD - avatar
+ 3
the one that is defined later! You can verify it with my code here: https://code.sololearn.com/WLRK8lr89209/#js
16th Dec 2016, 10:22 PM
Caffeinated Gamer YT
Caffeinated Gamer YT - avatar