jQuery.ready
Along with answers mentioned above on of the key things is you can pass data from php to javascript which is as follows
Passing values from PHP to Javascript with "Drupal.settings"
You can easily make variables from PHP available to Javascript on the front end with Drupal.settings using drupal_add_js() function
array('key' => 'value')), 'setting');
?>
or
'setting',
'data' => array('myModule' => array('key' => 'value')),
);
?>
This will be available in Javascript as:
if (Drupal.settings.myModule.key === 'value') {
alert('Got it!');
}