in general
- javascript is case sensitive!
- mind your brackets and curly brackets
- separate commands with a semi-colon ;
- layout-things such as new lines, tabs or spaces are of no importance or consequence: you can use them to make your script easier to read
most used commands
- jQuery(document).ready(function($) {[a_set_of_commands]}: a set of commands that is executed when the document is ready to be used
- .val(): read the value of an object
- .val([new_value]): set the value of an object
- .parent(): refer to the parent of an object
- .find("[type_of_object]"): find object of a certain type
- .keyup(function(){[set_of_commands]}): a set of commands to execute when something is entered in an object, for example in an input-box
- console.log([something_to_be_displayed]): writes something to be displayed in the console of the browser
- if ([expression]){[set_of_commands]}else{[set_of_commands]}
- == means 'equals'
- != means 'not equals' or 'is different from'
- .change(): set the status of an object to 'changed'
- .prop("[attribute]", "[new_value]"): set the attribute of an object to 'new value'
- .click(function(){[set_of_commands]}): a set of commands to execute when an object is clicked, for example a button
- $("#[name_of_select]").append($("<option />").val([new_code]).text([new_text])): add option to a select
About '===' (and '!=='): triple equals means 'equality without type coersion'. Using the double equals allows us to be sloppy. For example is we test 1=='1' the result will be 'true', because auto type coersion is on and the character '1' will be converted into the integer 1. However if we compare 1==='1' the result will be false, because they are of a different type.
And some love to use "shortcuts" like:
return months <= 0 ? 0 : months; meaning "evaluate if months is less than or equals zero; if true then return zero, if false
then return months".
Or myInt -= anotherInt; and that is the same as myInt = myInt - anotherInt;
this page was last reviewed July 2015