You have a problem with the scope
Since you did not use "var", you are redefining the global variable "a" (used as your function) with the number (3).
When you try to execute it a second time, this is no longer a function, but a number that causes a type error.
function a() { a = 3;
, What would you like
function a() { var a = 3;
Using var is almost always recommended inside a function; otherwise, you pollute or worse redefine global variables. In JS, var forces your variable into the local scope (your function).
Note that using var in a global scope still creates a global variable
source share