Home
My Highlights
Discover
Sign up
Code structure
javascript.info
putting semicolons between statements even if they are separated by newlines. Here, JavaScript interprets the line break as an “implicit” semicolon JavaScript does not assume a semicolon before square brackets [...]. can have as many statements in our code One-line comments start with two forward sl
12 Users
0 Comments
75 Highlights
0 Notes
Summary
- ⚠️ **Error Example**: The code `alert("Hello"); [1, 2].forEach(alert);` displays "Hello", then "1", then "2" correctly.
- ❌ **Semicolon Removal**: Removing the semicolon after `alert("Hello")` leads to only "Hello" being shown, with an error in the console.
- 🔍 **JavaScript Behavior**: JavaScript does not automatically insert a semicolon before square brackets, treating the code as a single statement.
- 🛑 **Misinterpretation**: The engine interprets the modified code as `alert("Hello")[1, 2].forEach(alert);`, which is incorrect.
- ✅ **Solution**: Always use semicolons appropriately to avoid such errors in your code.
Top Highlights
putting semicolons between statements even if they are separated by newlines.
Here, JavaScript interprets the line break as an “implicit” semicolon
JavaScript does not assume a semicolon before square brackets [...].
can have as many statements in our code
One-line comments start with two forward slash characters //.
Domain
javascript.info
Ready to highlight and find good content?
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.
Start Highlighting