Closed pranithsrujanroy closed 4 years ago
Why are you changing this?
It says - Both hello
and name
act generally as if they were declared with var
.
but name
being a function parameter is block scoped and behaves like a variable declared with let
.
In the later example of catch
block isn't it the similar case where err
is a parameter where it is written is block scoped and behaves as if declared with let
but name being a function parameter is block scoped and behaves like a variable declared with let.
This is not accurate. Parameters are available to the entire function, and thus act more like a var
. Moreover, you can do var paramName = ..
in the function body to "re-declare" a variable, unlike let
which would disallow such a re-declaration.
The way in which parameters do act more like a let
declaration is if you're using = ..
default parameter expressions, in which case you can violate the TDZ (which var
s do not have). So parameters are sorta like both, but I would claim they are much more like var
, especially historically, than like let
.
This is not accurate. Parameters are available to the entire function, and thus act more like a
var
. Moreover, you can dovar paramName = ..
in the function body to "re-declare" a variable, unlikelet
which would disallow such a re-declaration.then isn't is the same with
err
in catch block. I see the same scenario over there but there it is written it behaves more like a variable declared withlet
the variable name is a block scoped variable but it's confusing when said it behaves as a variable declared with var
Yes, I promise I've read the Contributions Guidelines
I already searched for this issue
Edition: 2nd
Book Title: You Don't Know JS Yet
Chapter: 2
Section Title:
Topic: