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

scope problem should be updated to ES2015 #296

Open
rshpeley opened this issue Feb 5, 2020 · 4 comments
Open

scope problem should be updated to ES2015 #296

rshpeley opened this issue Feb 5, 2020 · 4 comments

Comments

@rshpeley
Copy link

rshpeley commented Feb 5, 2020

The scope exercise defines scope in javascript before the ES2015 standard. Being 5 years later the ES2015 is probably the most used javascript now.

  1. enter javascripting
  2. select SCOPE
  3. you can see that only global and local scopes are referenced

Include block scope. Rename local scope to function scope.

Usage is defined at these two links from w3schools for let and const,

@ledsun
Copy link
Collaborator

ledsun commented Feb 5, 2020

I agree.

However, including the block scope feels a bit difficult.
I would like to reduce the description of function scope and instead compare global scope with block scope.

@itzsaga
Copy link
Member

itzsaga commented Feb 5, 2020

Yeah, having taught this to others I think removing function scope is okay for what javascripting is trying to achieve. We don't need to cover every part of JS and const & let are the most commonly used today IMO. Maybe a reference to var in the lesson so when people on their learning journey see it it's not a completely unknown.

@rshpeley
Copy link
Author

rshpeley commented Feb 5, 2020

@ledsun here's a bit of code based on the scope problem to show global and block scoping:

let [a, b, c] = [1, 2, 3]
console.log(`a: ${a}, b: ${b}, c: ${c}`)
       
{
  let [b, c] = [5, 6]
  console.log(`a: ${a}, b: ${b}, c: ${c}`)
  {
    let b = 8
    console.log(`a: ${a}, b: ${b}, c: ${c}`)
    {
      let [a, c] = [7, 9]
      console.log(`a: ${a}, b: ${b}, c: ${c}`)
      {
        let [a, c] = [1, 8]
        console.log(`a: ${a}, b: ${b}, c: ${c}`)
      }
      console.log(`a: ${a}, b: ${b}, c: ${c}`)
    }
    console.log(`a: ${a}, b: ${b}, c: ${c}`)
  }
  console.log(`a: ${a}, b: ${b}, c: ${c}`)
}
console.log(`a: ${a}, b: ${b}, c: ${c}`)

Running node scope.js gives:

a: 1, b: 2, c: 3
a: 1, b: 5, c: 6
a: 1, b: 8, c: 6
a: 7, b: 8, c: 9
a: 1, b: 8, c: 8
a: 7, b: 8, c: 9
a: 1, b: 8, c: 6
a: 1, b: 5, c: 6
a: 1, b: 2, c: 3

Putting this into problem form:

let [a, b, c] = [1, 2, 3]
       
{
  let [b, c] = [5, 6]
  {
    let b = 8
    {
      let [a, c] = [7, 9]
      {
        let [a, c] = [1, 8]
      }
    }
  }
}

Then solution form:

let [a, b, c] = [1, 2, 3]
       
{
  let [b, c] = [5, 6]
  {
    let b = 8
    console.log(`a: ${a}, b: ${b}, c: ${c}`)
    {
      let [a, c] = [7, 9]
      {
        let [a, c] = [1, 8]
      }
    }
  }
}

Gives the proper solution.

a: 1, b: 8, c: 6

Of course the preamble still needs to be reworked.

@ledsun
Copy link
Collaborator

ledsun commented Apr 13, 2020

I am looking at another issue(#125) and wondering if the problem statement @rshpeley presented is too difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants