0

Possible Duplicate:
What do parentheses surrounding a JavaScript object/function/class declaration mean?

Why following code does not work

function func() {
    document.writeln("HELLO");
}();

UPDATE:
Why in following example O should not use parentesis around "function{}"?

var v = function() {
   return "HELLO";
}();

document.writeln(v); ​

Community
  • 1
  • 1
Volodymyr Bezuglyy
  • 16,295
  • 33
  • 103
  • 133

2 Answers2

4

Use either this:

function func() {
    document.writeln("HELLO");
}

func();

Or this:

(function() {
    document.writeln("HELLO");
})();
VisioN
  • 143,310
  • 32
  • 282
  • 281
1

try:

(function() {
  document.writeln('HELLO');
})();
Sandeep Kumar
  • 13,799
  • 21
  • 74
  • 110