I was reading an article explaining function prototyping and inheritance in JavaScript when I came across these lines of code I can't wrap my head around
a = {}
(function(){}())
What exactly do these lines do?
I was reading an article explaining function prototyping and inheritance in JavaScript when I came across these lines of code I can't wrap my head around
a = {}
(function(){}())
What exactly do these lines do?
a = {} // Be 'a' an empty object (But why ?)
function(){ // Declare a function that says Hello when it's called
alert("Hello");
}
function(){ // Declare a function that says Hello and execute it immediately with ()
alert("Hello");
}()
function(){}() // Declare a function that...does nothing, and execute it immediately with ()... But apparently you can't, that's a syntax error (Thanks @pointy)
(function(){}()) // Makes it work (no syntax error)