/*
**********************************************
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
•...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.