ZAKAS OOP CHAPTER ONE : Data types

Notes and demo from Zakas Book

by nickadeemus2002

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

/*
**********************************************
ZAKAS OOP CHAPTER ONE : Data types
**********************************************
*/
//While JavaScript doesn’t have classes, 
//it does have types. Each variable or 
//piece of data is associated with a 
//specific primitive or reference type.

//Reference types are the closest thing 
//to classes in JavaScript, and objects 
//are instances of reference types.

/**
************************************************
* PRIMITIVE WRAPPER TYPES (String,Number, Boolean):
* literal values treated like objects using
* object methods
************************************************
*/
/*
//forces primitive wrapper type because of 
//new ObjectType 
//var myDog = new String('Bella Grace');
//console.log(typeof myDog); //gives 'object'
//console.log(myDog instanceof String);

//js weirdness: obj is always true when used
//for conditional check
//var boolObj = {}
var boolObj = new Boolean(false);
if(boolObj){
    console.log('boolObj was true');
}
*/

/*
//string primitive literal
//var dog= "Bella";
//treating literal like object
//var dogFirstLetter = dog.charAt(0);
//console.log(dogFirstLetter);
//but adding properties to string primitive
//literal wont work because of autoboxing -- 
//which only lasts one line!
var name = "Bella"; 
//js engine creates String obj so you can treat 
//like obj, but only for 1 line
name.middle = "Grace";
//temp name String Obj destroyed here
console.log(name.middle);
console.log(typeof name); 
//using literal, so typeof works and 
//doesn't return 'object'
*/

/**
************************************************
* BUILT-IN REFERENCE TYPES (read as objects):
* values stored in memory.
* variable stores pointer to value in memory
------------------------------------------------
• Array - An ordered list of numerically 
        indexed values
• Date - A date and time
• Error - A runtime error 
        (there are also several more specific
• Function - A function
• Object - A generic object
•...