Two Laptop Bag*
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript Coding Convention Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript Coding Convention" Watch "JavaScript Coding Convention" New topic
Author

JavaScript Coding Convention

Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
hi friends, my name is Jeffry. I'm new in here. I'm also new in Javascript. I want to know if the javascript has coding convention like Java programming language. does it has coding convention?


thanks

Jeffry Kristianto Yanuar
SCJP 5.0
SCJA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

To be honest, I've never heard of one. A lot of the common sense conventions carry over from Java, but were there specific areas you were wondering about?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
To be honest, I've never heard of one. A lot of the common sense conventions carry over from Java, but were there specific areas you were wondering about?


I have the book titled Sams Teach YourSelf JavaScript in 24 Hours. the author always create a method with a capital letter in the first letter. it confused me very much. There are no gap between variable asignment for example:




Does the javascript programmer code like above in the real project?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

Umm, well, I never had much respect for Sam's books....

In any case, I've never seem cap letters used for function names. Similar to Java, identifiers (be they functions or otherwise) are customarily created in camel case with an initial lowercase letter. JavaScript "classes", as in Java, start with a capital letter, and so on.

With regards to whitespace, I've seen lots of variations. I tend to use whitespace to make code more readable, but I don't think that there's one prevalent convention.
[ May 13, 2008: Message edited by: Bear Bibeault ]
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
I think it will be best if I simply use Java coding convention. I like SAMS 24 hours books because the book provide a faster way to learn. Thanks for replying.


Jeffry Kristianto Yanuar


SCJP 5.0
SCJA
 
jQuery in Action, 2nd edition
 
subject: JavaScript Coding Convention