- Joined
- Nov 17, 2019
- Messages
- 1,072
- Reaction score
- 499
- First Language
- English
- Primarily Uses
- RMXP
I wanted to ask you guys how the scope of variables work in Javascript to learn how they get affected depending on the place they are declared.
In Ruby I know that a local variable can be used inside any method and need to be passed to another method as an argument.
The same happens in C, C++ and Javascript. No problems here.
Yet, what happens if a let variable is defined inside a conditional statement?
Can we call it after the condition has been executed without getting an error message?
In Ruby that would work fine because it doesn't enforce any specific rule about local variables, but it wouldn't work in C and C++ at all. I'd need to define it outside that statement.
What about Javascript?
In Ruby I know that a local variable can be used inside any method and need to be passed to another method as an argument.
The same happens in C, C++ and Javascript. No problems here.
Yet, what happens if a let variable is defined inside a conditional statement?
Can we call it after the condition has been executed without getting an error message?
In Ruby that would work fine because it doesn't enforce any specific rule about local variables, but it wouldn't work in C and C++ at all. I'd need to define it outside that statement.
What about Javascript?
Last edited: