Skip to content

Instantly share code, notes, and snippets.

@RedSoxFan22
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedSoxFan22/116fd976c93378f12e3f to your computer and use it in GitHub Desktop.
Save RedSoxFan22/116fd976c93378f12e3f to your computer and use it in GitHub Desktop.
10:53
comments in JS start with //
define a variable with keyword var
there is no do and end in JS, we use open anc close brackets instead
parentheses around parameters
while(counter < array.legnth) is while(parameter)
implicit return in ruby, but not in JS. if you want a return, you have to write "return x"
how to puts: alert or console.log
white space is irrelevenat in JS, but we need semi-colons after every line.
but, like CSS, you can leave off the semi-colon on the last line (but, put it anyway).
no under_scores, use camelCase with first letter being lowercase
def (method) is in ruby, function is in JS
a float is the only kind of number in JS
use triple equals in JS, not the same as double equal. but, a deep comparison on a data structure like an array will return "false" in JS, because they are compared using the memory placement, which will not be the same.
node in terminal to run JS. ctrl+C Twice to exit, or .exit
Hashes in Ruby are called Objects in JS 11:14. there is nothing like a symbol, so to get something out of a hash/object use
a["string"] or a.item. In JS, keys are strings and that's it, but values can be anything.
the crazy thing about JS is that functions can be stored in variable. 11:31
to invoke a function with no parameters, still use parentheses cuber.run()
parens execute, lack of parens returns the function thing
you can return a function that returns a function (nested function)
option+command+j to get JS console in the bottom of any browser
JS is events and behaviors. 11:51
JS error message appear in the console
all JS goes into application.js 11:57
function defaultName() {
var field = document.getElementbyID("name_field");
field.value = "Defauuuuu";
}
going from block to none is how to get something that's hidden to be shown 12:02
to get an element by id, document.getElementById
to get an element by class, document.getElementsByClassName("copyable")
homework is toggling, showing hidden field, etc. Much of what was done in class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment