Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created November 29, 2012 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/4171244 to your computer and use it in GitHub Desktop.
Save rwaldron/4171244 to your computer and use it in GitHub Desktop.
function f(x, x, …rest) {}
Syntax Error: duplicate parameter name (Rule 1.A)
function f(x, {a:x, b:y}) {}
Syntax Error: duplicate parameter name (Rule 1.A)
function f([x]) { let x; }
Syntax Error: redeclaration of parameter x (Rule 1.B)
function f([x]) { var x; }
Syntax Error: redeclaration of parameter x (Rule 1.B)
function f([x]) { {var x;} }
Syntax Error: redeclaration of parameter x using hoisted var (Rule 1.B)
function f([x]) { {let x;} }
Valid, redeclaration is in inner block
function f([x]) { function x(){} }
Syntax Error: redeclaration of parameter x (Rule 1.B)
function f([x]) { class x {} }
Syntax Error: redeclaration of parameter x (Rule 1.B)
function f(x, y=x) {}
Valid, x has been initialized when y's default value expression is evaluated.
function f(x=y, y) {}
Runtime: ReferenceError exception y not initialized (Rule 2)
const a = "A";
function f(x=a) {}
Valid
function f(x=a) { var a;}
Runtime: ReferenceError a not yet initialized (Rule 2.A)
function f(x=a) { const a = "A";}
Runtime: ReferenceError a not yet initialized (Rule 2.A)
function a() {return "A";}
function f(x=a()) {}
Valid, a is initialized in surrounding scope, at time of parameter default value initialization.
function f(x=a()) { function a() { return "A"; } }
Runtime: ReferenceError a not yet initialized (Rule 2.A)
(6)
function f(x, y = 7) {
...
}
<===>
(5)
function f(x, y) {
let x1 = x;
let y1 = y ?? 7;
(5)
return (function(x, y) {
...
}).call(this, x1, y1);
}
WH: (whiteboard)
function f(x, x=7, z=x) {
let x1 = x;
let x2 = x ?? 7;
let z1 = z ?? which x?;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment