Assigned value is discarded when exiting an inner scope
See original GitHub issueask {
let a = 2
let c = 'Hello'
if(a < 5) {
c = '!'
}
return c
}
returns Hello
instead of !
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12
Top Results From Across the Web
c++ - Are variables inside a loop (while or for) disposed after ...
Outside the scope that particular variable even doesn't exits, forget about accessing its value. for(;;) { int var; // Scope of this variable...
Read more >Discards - unassigned discardable variables - Microsoft Learn
Discards are placeholder variables that are intentionally unused in application code. Discards are equivalent to unassigned variables; they don' ...
Read more >Variable scope, closure - The Modern JavaScript Tutorial
When the code wants to access a variable – the inner Lexical Environment is searched first, then the outer one, then the more...
Read more >Variables and scope - Object-Oriented Programming in Python
To define a new variable in Python, we simply assign a value to a label. For example, this is how we create a...
Read more >2.5 — Introduction to local scope - Learn C++
A local variable's scope begins at the point of variable definition, and stops at the end of the set of curly braces in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mhagmajer I dug a little into the runner. It seems like that
c = '!'
redeclaresc
with alet
. When running @czerwinskilukasz1 's test, I get this object:In the statements inside
fun.ts
compute
method. Since it is a scopedlet
statement, it is, well… scoped 😃It seems like the scope is lost when![losingScope](https://user-images.githubusercontent.com/6459899/84984884-62b2d100-b144-11ea-9e5f-c5c12e6f6d69.gif)
fragments.ts
callsfun.compute
on a block.@YonatanKra I think we should throw a runtime error on when someone attempt to assign value to a undeclared variable. It’s the same like trying to read an undeclared variable - we throw in that case already