scope-chains-closures icon indicating copy to clipboard operation
scope-chains-closures copied to clipboard

Issues with tests for scopes challenge

Open arku opened this issue 8 years ago • 7 comments

The challenge asks us to create a function foo and lexically scope a variable bar. My solution was

var foo = function(){
  var bar;
}

However one of the tests fail. I think the above solution is also right and should be accepted. Correct me if I am wrong.

arku avatar Jun 22 '16 14:06 arku

The solution is below:

function foo() {
    var bar
}

lenguyenthanh avatar Sep 22 '16 13:09 lenguyenthanh

@lenguyenthanh I've been running into the same problem. I tried your solution but I get a syntax error. Same if I try function foo(){ var bar; } Anybody any ideas what I'm doing wrong?

LisaMieth avatar Oct 10 '16 04:10 LisaMieth

@LisaKhadijah what is your syntax error? It looks correct.

lenguyenthanh avatar Oct 10 '16 04:10 lenguyenthanh

@lenguyenthanh I don't get any specific error. If i run scope-chains-closures verify <myfile.js> all I get is the console message "syntaxerror".

LisaMieth avatar Oct 10 '16 05:10 LisaMieth

@lenguyenthanh shouldn't @arun1595 solution be valid too though?

domfarolino avatar Jan 05 '17 19:01 domfarolino

@lenguyenthanh the solution of @arun1595 is a valid kind to define a function. this workshop shouldn't make a difference between function declaration and function expression.

NonPolynomial avatar Feb 22 '17 21:02 NonPolynomial

Assigning a function to a variable did not give it a name in Node versions prior to 6:

var foo = function () {}
console.log(foo.name)
console.log((function bar() {}).name)

So that, and I think that the validation is harder were the reasons why this doesn't work. A PR that fixes this would be good imo.

martinheidegger avatar Feb 23 '17 00:02 martinheidegger