JavaScript 101
André Odendaal
Background
Netscape Navigator
Designed by Brendon Eich in 1995
Built to replace Java for the web and be “easy to use”
Prin...
Basic Types
number
Only 64-bit floating point
No integers, longs, doubles, signed or unsigned to complicate matters
Associ...
Objects
Object Literals
Dynamic (not based on pre-defined class) collection of properties
Property names must be a unique ...
Demo – Objects
Object Types
Arrays
Special object with index as property names (not associative)
Has properties like: length, sort(), fil...
Demo – Objects
Revisited
Other Types
null
Nothing

undefined
Less than nothing
Functions
Composition
Made up of 4 parts: function, name (optional), parameters, set of statements
2 additional parameters...
Demo – Invoking Functions
Inheritance with Prototypes
Prototype with functions
All functions have a property prototype as a base object
Use new keyw...
Demo - Prototyping
Questions?
Upcoming SlideShare
Loading in...5
×

JavaScript fundamental data types and functions

419

Published on

A look at the data types and how functions are invoked in JavaScript

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
419
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Value defaults to undefinedWritable defaults to falseConfigurable defaults to falseEnumerable defaults to falseGet defaults to undefinedSet defaults to undefined
  • Method: local objectFunction: global object // mistake, should be outer function this objectthat work-aroundConstructor: new objectApply: choose, list of parameters
  • JavaScript fundamental data types and functions

    1. 1. JavaScript 101 André Odendaal
    2. 2. Background Netscape Navigator Designed by Brendon Eich in 1995 Built to replace Java for the web and be “easy to use” Principles from Java (syntax), Self (prototypes) & Scheme (functional) Rushed to market with good, bad & questionable design choices Microsoft created Jscript, a compatible dialect to avoid trademark issues ECMA Standardized by ECMA (European Computer Manufacturers Association) Called ECMAScript between Netscape & Microsoft Latest version 5 includes “strict mode” for more thorough error checking
    3. 3. Basic Types number Only 64-bit floating point No integers, longs, doubles, signed or unsigned to complicate matters Associative Law does not hold for some values (a + b) + c === a + (b + c) string 0 or more 16-bit Unicode (UCS-2) characters. No character type boolean true & false
    4. 4. Objects Object Literals Dynamic (not based on pre-defined class) collection of properties Property names must be a unique string within the object Basic Operations – Get, Set & Delete object.name | object[name] object.name = value | object[name] = value delete object.name | delete object[name] Property Named collection of attributes ES5 added functionality to define properties and added Get, Set functions Attributes: value, writable, configurable, enumerable, get, set
    5. 5. Demo – Objects
    6. 6. Object Types Arrays Special object with index as property names (not associative) Has properties like: length, sort(), filter() RegEx Regular expression object 2 primary methods exec() returns a match and test() returns boolean Functions An object which can be invoked with parentheses ()
    7. 7. Demo – Objects Revisited
    8. 8. Other Types null Nothing undefined Less than nothing
    9. 9. Functions Composition Made up of 4 parts: function, name (optional), parameters, set of statements 2 additional parameters: arguments object & this (invocation context) Invocation Method – this is the local object Function – this is the global object Apply – this is passed as a parameter Constructor – this is the new object Calling Assigning less parameters will make them undefined
    10. 10. Demo – Invoking Functions
    11. 11. Inheritance with Prototypes Prototype with functions All functions have a property prototype as a base object Use new keyword with function invocation to create new objects Constructor functions should start with a capital letter Inheritance If object doesn’t have a property look in base object
    12. 12. Demo - Prototyping
    13. 13. Questions?
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×