The following is a description of the JS material that I am currently learning.
const user=['Taro Tanaka', 'Ichiro Sato', 'Jiro Yamada'];
constresult=user.map(element=>{
return element + 'Mr';
})
console.log(result);
The first and fifth lines have semicolons (;
) at the end.On the other hand, the third line is attached in the middle.What kind of rule is this based on?I don't know the rules, so I find it very difficult to remember.I didn't really understand even if I googled, so I asked you a question.Thank you for your cooperation.
const user=['Taro Tanaka', 'Ichiro Sato', 'Jiro Yamada'];
return element+';
console.log(result);
These are all one 文statement. br
The sentence ends with a semicolon ;
.
(JavaScript has this semicolon auto-insert function, which is fine in most cases without it, but there are exceptions, so I always do.)
const result=user.map(element=>{
return element+';
})
This is also a single sentence, so you really need a semicolon after the third line )
.
However, it will be automatically inserted even if it is not as mentioned above, so there will be no error.
I think the following JavaScript syntax is easy for beginners to understand.
Statements and expressions ·JavaScript Primer#jsprimer
© 2024 OneMinuteCode. All rights reserved.