I'm wondering why this works
(function Test() {
alert('x');
}())
but this doesn't work
function Test() {
alert('x');
}()
How does the outer parenthesis change the precedence of things and make it work?
I'm wondering why this works
(function Test() {
alert('x');
}())
but this doesn't work
function Test() {
alert('x');
}()
How does the outer parenthesis change the precedence of things and make it work?
You can image the parenthesis is use for be explicit on what you do. Like when you do some operation like 3 * 2 + 4 or 3 * (2 + 4). When you do
function Test() { alert('x'); }()
The navigator just see 2 parenthesis alone whereas when you do
(function Test() { alert('x'); }())
It see you want to execute the function.