Tell us what’s happening:
So I understand what is going on. I have passed this part of the curriculum. I really just have a question. My question is about the semi colon on this specific string. The test passes with or without the semi colon. Why is that? How come I dont need the semi colon here. Is there a reason? Thats honestly the question i’m wondering about. Your code so far
// Only change code below this line
var myStr ="This is the first sentence. "
myStr += "This is the second sentence."
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.
Challenge: Concatenating Strings with the Plus Equals Operator
There are different kinds of semicolons in JS. The end of the line semicolons that are nor required in a sense because JS will add them in automatically for you while compiling, behind the scenes. There are debates over whether or not to use them - some people always add them in, others are adamant to leave them out. There are a few edge cases where it can make a difference, but very few.
There are also semicolons that must be there, like in a for loop. Those are not optional.
There are places where you need a semi colon and there are places where you don’t need it. I don’t know for sure but to make sure you never miss one that is needed, it is good practice to always add one.
the difference is that in previous challenges the tests were checking if the semicolon was there, as the challenges become more complex it is difficult to test for small things like that, it would make the challenge to restrictive, so it’s left to you to add them
Yeah, there are definitely heated sides to this debate. I used to work with a team that was adamantly anti-semicolon. And I’ve worked on teams where they were required (enforced by linters). My personal feeling is that they do add a tiny bit of clarity to the code and that they do prevent a few edge-case gotchas. I use semicolons.
Wow, thanks for clearing that up. I know it seems trivial to ask a question like this but im super ocd about directions lol. From now on I WILL be using semicolons.