Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<base href="http://docs.jquery.com" />
<script src="http://code.jquery.com/jquery-1.3.js"></script>
  
<style>
</style>
</head>
<body>
  <div>one</div> <div>two</div> <div>three</div>
<script>
  //case 1  //  When the keyword function appears after '=' or '('                  
  //            the compiler knows this must be a function definition expression
  //            and allows you to call it immediately. 
  //case 2  //  When the keyword function starts a new statement the compiler assumes it to be a
  //            function declaration statement and hence you can't call the function immediately.
  
 
  function ()    {alert('1')}   ()                   //NOT valid. case 2  - so can't call immediately
  //function aaa()   {alert('1')}  ()                  //NOT valid. case 2  - so can't call immediately
  //(function ()   {alert('1')})  ()                   //valid -  case 1 .the global Wrapper is exectuing it
  //(function aa()   {alert('1')})  ()                 // valid - case 1 .the global Wrapper is exectuing it
  // var t=function ()    {alert('1')}   ()            //valid -  case 1 . after '=' so fine.
  // var t=function aaa()    {alert('1')}   ()         //valid -  case 1 . after '=' so fine.
  // var t=(function aaa()    {alert('1')}   ())()     //valid -  case 1 . after '(' so fine.
                                          
 
  
  
</script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers