javascripting
javascripting copied to clipboard
scope problem should be updated to ES2015
The scope exercise defines scope in javascript before the ES2015 standard. Being 5 years later the ES2015 is probably the most used javascript now.
- enter
javascripting - select SCOPE
- you can see that only
globalandlocalscopes are referenced
Include block scope. Rename local scope to function scope.
Usage is defined at these two links from w3schools for let and const,
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.
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.
@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.
I am looking at another issue(#125) and wondering if the problem statement @rshpeley presented is too difficult.