Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAaron Noble
6,559 PointsWhat sign acts as the closing tag in JavaScript, like a period at the end of a sentence?
I thought it was the '>' which was being used to close the </script> tag for Javascript. Could someone please explain the closing tag for Javascript? Thank you, Aaron!
ale8k
8,299 PointsIn JavaScript, each line of code is called a statement. Not we don't actually have to use ';' to declare a statement end in most cases but we do to stop unwanted bugs occurring in our code by accident. I will show you an example of a few cases where the ';' is used:
let myVar = 0; // Variable declaration and initialisation
let myVar; // Variable declarion
object.method(); // function calling
object.property; // property calling
/*
For example, we assign the length of a string literal (also an object) to a new variable and because all this is being
done in a single statement, we end it with a ';' otherwise it looks inconsistent and messy
*/
let myNameLength = 'Alex'.length; // See how it looks much neater with a ';' and let\'s us know the statement ends there.
// the result also is 4 stored in myNameLength :) which again, we can call.
myNameLength; // you wouldn't see anything but that inside of a console will display 4 :)
I hope this helps understanding syntax of JavaScript a little more. Some of the terms I have used may be unfamiliar to you but I recommend you visit MDN https://developer.mozilla.org/en-US/ and check out some of the things I've mentioned. Don't worry about anything, it is all just rules and regulations really of the language designers. HTML which uses </> is just another set of rules set for HTML. Good luck learning Aaron!
1 Answer
Aaron Noble
6,559 PointsThank you both for the helpful answers and resources! I'm looking at https://developer.mozilla.org/en-US/ right now and learning more and more! Thank you again
ale8k
8,299 PointsNo problem :) it should be your go-to resource, I advise against W3C schools as a lot of the info on their is actually wrong lol.
stjarnan
Front End Web Development Techdegree Graduate 56,488 Pointsstjarnan
Front End Web Development Techdegree Graduate 56,488 PointsHi Aaron Noble,
You tell JavaScript that you're done by using a ; sign, for example like this:
console.log('See the sign at the end of this line?');
You will soon start using separate files for JavaScript, and it will make more sense to you by then :)
Good luck!