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 trial

JavaScript JavaScript Basics (Retired) Introducing JavaScript Your First JavaScript Program

Is ; optional ?

So is ; optional in javascript. If so is it best practice to use ; and why

Thank you

2 Answers

Jesus Mendoza
Jesus Mendoza
23,289 Points

JavaScript adds ; at the end of every statement, so, If you don't use it in the wrong place it can lead to bugs

Ceil-Ian Maralit
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ceil-Ian Maralit
Front End Web Development Techdegree Graduate 19,434 Points

";" are important when writing JavaScript. As said in the video, it is like grammar. Think of it as a period on the end of every sentences, but with JavaScript it is more strict on using it at the end of your lines of code.

If you did not put ; at the end or forgot to put it, it will throw you an error. which is hard to find if you have massive lines of code. You will eventually stumble through one the courses here at treehouse that teaches you best practices of writing codes in JS.

Happy Coding!