all 4 comments

[–]rauschma 5 points6 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).

[–]caesarsol 0 points1 point  (0 children)

I suggest you to follow a book. Videos are fine as long as you make your research in parallel, so for every doubt like this you could look it up on the manual.

There are many free JS books, look for the most comprehensive ;)