Javascript Notes
Javascript Notes
JavaScript
• Like PHP, JavaScript is a modern programming language
that is derived from the syntax at C.
• Just like CSS with <style> tags, you can directly write your
JavaScript between <script> tags.
• Just like CSS with <link> tags, you can write your JavaScript in
separate files and link them in by using the src attribute of the
<script> tag.
JavaScript
• Including JavaScript in your HTML
• Just like CSS with <style> tags, you can directly write your
JavaScript between <script> tags.
• Just like CSS with <link> tags, you can write your JavaScript in
separate files and link them in by using the src attribute of the
<script> tag.
JavaScript
• Variables
$x = 44;
JavaScript
• Variables
$x = 44;
JavaScript
• Variables
var x = 44;
JavaScript
• Conditionals
• All of the old favorites from C are still available for you to use.
if
JavaScript
• Conditionals
• All of the old favorites from C are still available for you to use.
if
else if
JavaScript
• Conditionals
• All of the old favorites from C are still available for you to use.
if
else if
else
JavaScript
• Conditionals
• All of the old favorites from C are still available for you to use.
if
else if
else
switch
JavaScript
• Conditionals
• All of the old favorites from C are still available for you to use.
if
else if
else
switch
?:
JavaScript
• Loops
• All of the old favorites from C are still available for you to use.
JavaScript
• Loops
• All of the old favorites from C are still available for you to use.
while
JavaScript
• Loops
• All of the old favorites from C are still available for you to use.
while
do-while
JavaScript
• Loops
• All of the old favorites from C are still available for you to use.
while
do-while
for
JavaScript
• Functions
function(object);
JavaScript
• Objects
function(object);
JavaScript
• Objects
object.function();
JavaScript
• Objects
foreach($array as $key)
{
// use $key in here as a stand-in for $array[$i]
}
JavaScript
• Loops (redux)
foreach($array as $key)
{
// use $key in here as a stand-in for $array[$i]
}
JavaScript
• Loops (redux)
nums = nums.map(function(num) {
return num * 2;
});
JavaScript
• Functions (redux)
nums = nums.map(function(num) {
return num * 2;
});
JavaScript
• Functions (redux)
nums = nums.map(function(num) {
return num * 2;
});
JavaScript
• Events
function alertName(event)
{
var trigger = event.srcElement;
alert('You clicked on ' + trigger.innerHTML);
}
JavaScript
function alertName(event)
{
var trigger = event.srcElement;
alert('You clicked on ' + trigger.innerHTML);
}
JavaScript
function alertName(event)
{
var trigger = event.srcElement;
alert('You clicked on ' + trigger.innerHTML);
}