Just did a little brushing up on JavaScript generally going through this JS basics page, then moseying over the Mozilla Developer Network (MDN) pages for further reading. I also have JavaScript: The Good Parts on hand to chug my way through, though I think that may be ongoing and involve more practice/ trying things out, too.
- Use a function expression (
var myCode = function(a, b) {stuff;};
) rather than a function declaration (function myCode (a, b) {stuff;};
). Finally got a good explanation for this here: "To quote Ben Cherry’s excellent article: 'Function declarations and function variables are always moved ("hoisted") to the top of their JavaScript scope by the JavaScript interpreter.'" - Consider scope! Variables declared without
var
are global, so (almost) always usevar
. - Hooray for OOP. I do like putting things in boxes and generally tidying up.
- Object literal syntax: var thingy = {property1: 'value', property2: 'value';}; Point: if value is a function (rather than a primitive?), then the property is a method.
- Dot notation: objectname.propertyname
- Bracket notation: objectname['propertyname']
- While I can handle
this
, I don't particularly likethis.
- Ternary operators, shorthand for if/else:
var status = ( a === 'aaaa' ) ? 'Panic' : 'Calm';
(had a hard time coming up with a neutral for this one. Essentially: For status, if value of a is panicked screaming, assign value of "Panic" to status. Otherwise, assign value "Calm.")(Personally I much prefer "Don't Panic" to "Keep Calm and Carry On," particular since the latter has been so overused lately) - Further reading on JS overview here was very helpful for just clarifying where it stands in relation to Java and ECMAScript, plus some basic properties. Once I found MDN, I abandoned old W3Schools.
- I need a better understanding of how code executes. Closures? Hoisting? ack.
- So, scope?
Things read:
& all the links at the bottom of the JS Basics page.
This bit on JS closures (still not sure I understand).
And "If Hemingway Wrote JavaScript," which is amusing even if you don't know anything about code.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.