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) Storing and Tracking Information with Variables Create a variable with a string

Avery Kachline
Avery Kachline
10,458 Points

In 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

app.js
var player = 'Jasmine';
document.write(player);
index.html
<!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
PLUS
William Li
Courses Plus Student 26,865 Points

Yes, 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
PLUS
William Li
Courses Plus Student 26,865 Points

Hi, 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
Charles Smith
7,575 Points

Oh, 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
Charles Smith
7,575 Points

Semicolons 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