User:Jarle Pahr/Javascript: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
Line 59: Line 59:
Substrings:
Substrings:
  "wonderful day".substring(3,7)
  "wonderful day".substring(3,7)
Class prototypes:
Inheritance:
Penguin.prototype = new Animal();

Revision as of 05:45, 25 September 2013

http://en.wikipedia.org/wiki/JavaScript

https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript

https://itunes.apple.com/us/itunes-u/programming-abstractions/id384232917

http://www.codecademy.com/courses/javascript-beginner-en-x9DnD/0/1?curriculum_id=506324b3a7dffd00020bf661


Examples

Function definition:

var multiplybytwo = function (number) {
   var val = number * 2;
   console.log(val);
};


Declare a variable:

var myage = 25;


Confirm dialog:

confirm("You rock!")

Print to screen:

console.log('Hello world')


Equal to:

console.log(5 === 7)

Not equal to:

A !== B


If:

if condition //if  condition is true
{
 execute some code
}

If/else:

if condition
{
    execute some code
}
else
{
execute some other code
}

Substrings:

"wonderful day".substring(3,7)

Class prototypes:

Inheritance:

Penguin.prototype = new Animal();