Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function myFunc( requiredA, requiredB,  optionalA, optionalB, optionalC ) {
  switch (arguments.length - 2) { // 2 is number of required arguments
    case 0:  optionalA = 'Some default';
    case 1:  optionalB = 'Another default';
    case 2:  optionalC = 'Some other default';
  }
  console.log( requiredA, requiredB, optionalA, optionalB, optionalC );
  
}
myFunc( 'test', 1 );
myFunc( 'test', 2, 'override' );
myFunc( 'test', 3, 'override', false );
myFunc( 'test', 4, 'override', false, undefined );
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers