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,270 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
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!