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
  • 15,277
  • 31
  • 100
  • 129

2 Answers2

4

Use either this:

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

func();

Or this:

(function() {
    document.writeln("HELLO");
})();
VisioN
  • 138,460
  • 30
  • 271
  • 271
1

try:

(function() {
  document.writeln('HELLO');
})();
Sandeep Kumar
  • 13,202
  • 19
  • 67
  • 103