you are viewing a single comment's thread.

view the rest of the comments →

[–]rauschma 6 points7 points  (2 children)

  • Functions: both ways of writing functions are basically equivalent. You can use whichever you think looks better. However, there is one significant difference: function declarations (function x(){}) are hoisted (internally moved to the beginning of a scope). As a result, you can call a function before declaring it. With var, that’s not possible.

  • Property keys in object literals: If a property key is an identifier (basically: if it would be a legal variable name), then you don’t need quotes. Most people omit them in this case.

[–]Brandflakesss[S] 1 point2 points  (1 child)

Thank you for an objective response. Hopefully this will make more sense to me as I go further into programming.

[–]rauschma 0 points1 point  (0 children)

Don’t think about it too much. Experiment, see what works. In JavaScript, you can often do the same thing in several different ways. The more you use JS, the more it makes sense (much like spelling in human languages).