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 trialAvery Kachline
10,458 PointsIn the code Challenge the (;) is not mandatory Is this an error or the function does not need a (;)
I did it with at without the (;) both ways worked
var player = 'Jasmine';
document.write(player);
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
3 Answers
William Li
Courses Plus Student 26,868 PointsYes, the use of semicolon ; is optional in this case, but it's considered best practice to put a semicolon after every statement in JavaScript.
William Li
Courses Plus Student 26,868 PointsHi, Charles Smith , actually the Github style guide in your link isn't for JavaScript, it's a style guide for CoffeeScript. Yeah, I know, the title of page can be misleading, but you can tell from the code examples there, that's CoffeeScript code.
a while ago, Github made a choice to write all the new Js codes on their codebase in CoffeeScript.
If you need a good JavaScript style guide, here're couple of good ones -- AirBnB JavaScript style guide, and Google's JavaScript Style guide.
Charles Smith
7,575 PointsOh, thanks. I haven't focused much on JS but I remembered reading the Ruby style guide the other day so I figured I'd check out the JS one.
I guess maybe it's serendipity that the rails track changed and I have to do JS basics again.
Charles Smith
7,575 PointsSemicolons are a style choice in a lot of places in JS. Github's JS style guide actually encourages you to omit them (at least, in examples like the one you posted). https://github.com/styleguide/javascript
Here are some other resources:
http://stackoverflow.com/questions/4002234/do-we-need-semicolon-at-the-end
which will lead you to:
http://inimino.org/~inimino/blog/javascript_semicolons