Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,273 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,421 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!