Add additional examples about const, let, var and block scopes#26
Open
JuhQ wants to merge 2 commits into
Open
Conversation
Reviewer's GuideThis PR updates the JavaScript basics documentation by normalizing indentation in code samples and adding a new section that explains JavaScript variable scope, contrasting block-scoped let/const with function-scoped var using simple examples and explanations. State diagram for variable visibility in block and function scopesstateDiagram-v2
[*] --> Global_scope
state Global_scope {
[*] --> No_variables
No_variables --> Has_var_x: Declare_var_x_in_if_block
Has_var_x --> Global_access_x_ok: Access_x_outside_if_block
Has_var_x --> Call_test_function: Call_test
Call_test_function --> Call_test_function: Reenter_test_if_called_again
Call_test_function --> Global_access_y_error: Access_y_outside_function
No_variables --> Enter_block_let_const: Enter_if_block_and_declare_let_const
Enter_block_let_const --> Block_scope
}
state Block_scope {
[*] --> Let_const_visible
Let_const_visible --> Exit_block: Reach_closing_brace
Exit_block --> [*]
}
Global_access_x_ok --> [*]
Global_access_y_error --> [*]
Enter_block_let_const --> Has_let_a_const_b
Has_let_a_const_b --> Exit_block
state Has_let_a_const_b {
[*] --> Inside_block_a_b_defined
Inside_block_a_b_defined --> [*]
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The new section uses
js code fences while the rest of the file usesjavascript; consider standardizing the language tag for consistency in syntax highlighting. - You removed the leading indentation from many existing code blocks; please double-check that this matches the formatting conventions used in the rest of the documentation so code samples render consistently.
- The use of emojis and symbols (✅, ❌) in the new block-scope section may not match the tone of the rest of the document; consider replacing them with plain-text descriptions if a more neutral style is preferred.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new section uses ```js code fences while the rest of the file uses ```javascript; consider standardizing the language tag for consistency in syntax highlighting.
- You removed the leading indentation from many existing code blocks; please double-check that this matches the formatting conventions used in the rest of the documentation so code samples render consistently.
- The use of emojis and symbols (✅, ❌) in the new block-scope section may not match the tone of the rest of the document; consider replacing them with plain-text descriptions if a more neutral style is preferred.
## Individual Comments
### Comment 1
<location> `vuorovaikutteiset_ohjelmat.md:289` </location>
<code_context>
```javascript
- const name = prompt('Type your name.');
- console.log('Noice to meet you, ' + name);
+const name = prompt('Type your name.');
+console.log('Noice to meet you, ' + name);
</code_context>
<issue_to_address>
**issue (typo):** Possible typo in greeting text: "Noice" vs "Nice".
The string "Noice to meet you" is likely a misspelling of "Nice to meet you". If it’s not intentional, please update it to improve clarity.
```suggestion
console.log('Nice to meet you, ' + name);
```
</issue_to_address>
### Comment 2
<location> `vuorovaikutteiset_ohjelmat.md:203` </location>
<code_context>
The type of the variable can be tested with `typeOf`-operation:
```javascript
- const name = 'Ahmed';
</code_context>
<issue_to_address>
**issue (typo):** Incorrect casing in `typeof` operator name.
Consider updating the sentence to: “The type of the variable can be tested with the `typeof` operator:” so the operator name matches JavaScript’s actual syntax.
```suggestion
The type of the variable can be tested with the `typeof` operator:
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| const name = prompt('Type your name.'); | ||
| console.log('Noice to meet you, ' + name); | ||
| const name = prompt('Type your name.'); | ||
| console.log('Noice to meet you, ' + name); |
There was a problem hiding this comment.
issue (typo): Possible typo in greeting text: "Noice" vs "Nice".
The string "Noice to meet you" is likely a misspelling of "Nice to meet you". If it’s not intentional, please update it to improve clarity.
Suggested change
| console.log('Noice to meet you, ' + name); | |
| console.log('Nice to meet you, ' + name); |
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds a new section to the
vuorovaikutteiset_ohjelmat.mddocumentation that explains JavaScript variable scope, specifically the differences betweenlet,const, andvar. The new content uses clear analogies and examples to help readers understand block scope versus function scope.Additions to documentation about variable scope:
letandconst, including examples and analogies to clarify that variables declared with these keywords are only accessible within their enclosing block.varis function-scoped rather than block-scoped, with illustrative code samples showing its behavior inside and outside of functions.Summary by Sourcery
Update JavaScript documentation for interactive programs with clearer examples and introduce an explanation of variable scoping.
Documentation: