02 the grammar of java script
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

02 the grammar of java script

on

  • 585 views

 

Statistics

Views

Total Views
585
Views on SlideShare
585
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

02 the grammar of java script Presentation Transcript

  • 1. THE GRAMMAR OFJAVASCRIPT
  • 2. A statement is asingle step•  Ended by a semicolonalert(Liz Lemon);!alert(!Liz Lemon!);!•  … but not …alert(Liz!Lemon);!
  • 3. JavaScript is case-sensitivealert("This works");Alert("This does not work");ALERT("This doesnt either");
  • 4. There are many built-in functions•  alert()•  document.write()•  console.log()•  eval()•  String functions•  Number functions•  Window functions•  Date functions•  Math functions•  Many, many more
  • 5. JavaScript is dynamically typed•  Numbers•  Strings•  Boolean
  • 6. Variables store data•  var firstName;•  var lastName = Donaghy;•  var age = 50;•  var isAwesome = true;
  • 7. Numbers are very flexible•  var x = 5; // Integer•  var x = 5.5; // Floating point•  var x = 050; // Octal 50•  var x = 5.0e50; // Scientific notation
  • 8. BooleansIf you do this ... The result is ...if (true) {}! trueif (false) {}! falseif ("Tracy Jordan") {}! trueif ("") {}! falseif ("false") {}! true (b/c it isnt null)if (100) () ! trueif (0) ()! falseif (100/0) {}! falsea = 75;! trueif (a) {}!c = 34;! falseif (d) {}!
  • 9. Simple operators+ - * / % ( )
  • 10. Combining numbers and strings•  var tries = "12";•  var x = "You have " + tries + " more attempts.";•  implicitly converts numbers to strings•  var x = 5 + tries; // 512•  var x = 5 + +tries; // 17•  var x = 5 + Number(tries); // 17
  • 11. Auto-assignment operators•  x += 5; same as x = x + 5;•  x -= 5; same as x = x - 5;•  x *= 5; same as x = x * 5;•  x /= 5; same as x = x / 5;•  x++; same as x = x + 1;•  x--; same as x = x - 1;
  • 12. Arrays•  var days = [Mon, Tues, Wed, Thu, Fri ];•  x = days[0]; //Mon•  y = 1;•  x = days[1+2]; //Thu•  x = days[days.length-1]; //The last element
  • 13. Making queues and stacksvar numElements = a.push(newVal);!var thingRemoved = a.pop();!var numElements = a.unshift(newVal);!var thingRemoved = a.shift();!
  • 14. Objects in JavaScript are dynamic•  You dont create classes, you just create objects on the flyvar person1 = {! lastName: "Cooper",! firstName: "Sheldon",! title: "PhD",! greet: function(targetFirstName) {! for (var i=1 ; i<=3 ; i++) {! knockOnDoor();! alert(targetFirstName);! }! }!};!
  • 15. JavaScript … •  Can manage encapsulation fairly well •  Can awkwardly inherit through prototyping •  Can have polymorphism •  But cannot do them simultaneouslyJavaScript hasobjects but is notobject-oriented
  • 16. Instantiating and referring to objects•  var theThingy = new Whatever();•  var x = theThingy.aProperty;•  theThingy.doSomething();
  • 17. var x; // Everything to the right of slashes!/*!Anything between slash-splat and !splat-slash are comments.!*/! You can comment your code
  • 18. Conclusion•  Data Types•  Operators•  Arrays•  Objects