Avothr Avothr - 1 month ago 10
Javascript Question

JavaScript function close() {}

I've created a function in JS named close

function close() {...}


and have an onclick call

onclick="close()"


but it won't work. If I rename the function to whatever, it works. Could it be that it is forbidden to use a function in JS named close() ?

Answer

close is a method of window. Like all objects from window, you can call it without window prefix.

console.log(typeof close);