Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: closure example #1770

Open
wants to merge 1 commit into
base: 2nd-ed
Choose a base branch
from
Open

Conversation

ulayab
Copy link

@ulayab ulayab commented Dec 13, 2021

Yes, I promise I've read the Contributions Guidelines (please feel free to remove this line).

Specifically quoting these guidelines regarding typos:

Typos?

Please don't worry about minor text typos. These will almost certainly be caught during the editing process.

If you're going to submit a PR for typo fixes, please be measured in doing so by collecting several small changes into a single PR (in separate commits). Or, just don't even worry about them for now, because we'll get to them later. I promise.


Please type "I already searched for this issue":
I already searched for this issue
Edition: (pull requests not accepted for previous editions)
2nd
Book Title:
Scope & Closures
Chapter:
apA.md
Section Title:
var and let
Topic:
example code

The example code will cause a SyntaxError: Unexpected token '.' by record.name.

function getStudents(data) {
    var studentRecords = [];

    for (let record of data.records) {
        let id = `student-${ record.id }`;
        studentRecords.push({
            id,
            record.name  // <---- SyntaxError: Unexpected token '.', fixed this line to `name: record.name`
        });
    }

    return studentRecords;
}
             record.name
                  ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

@getify
Copy link
Owner

getify commented Dec 13, 2021

Good catch! Thanks.

@getify getify force-pushed the 2nd-ed branch 9 times, most recently from 7916ced to 57e740a Compare January 25, 2022 23:53
@getify getify force-pushed the 2nd-ed branch 12 times, most recently from bf58419 to bae21ee Compare February 17, 2022 00:02
@getify getify force-pushed the 2nd-ed branch 5 times, most recently from 23d8b7b to e909d38 Compare July 16, 2022 14:49
@getify getify force-pushed the 2nd-ed branch 2 times, most recently from 29c2978 to 667c741 Compare August 3, 2022 14:27
@getify getify force-pushed the 2nd-ed branch 6 times, most recently from ec72a23 to 976d472 Compare August 24, 2022 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants