镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

scope problem should be updated to ES2015 #296

Description

@rshpeley

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,

Activity

  1. ledsun commented on Feb 5, 2020

    @ledsun
    Collaborator

    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.

  2. itzsaga commented on Feb 5, 2020

    @itzsaga
    Member

    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.

  3. rshpeley commented on Feb 5, 2020

    @rshpeley
    Author

    @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.

  4. ledsun commented on Apr 13, 2020

    @ledsun
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions