by => Jordan Hayashi
Interpretor
var fisrtname = "art";
var lastname = "dvp";
var arr = ['student' , 23,true , function(){
console.log('hi')
}];
//hi
for(var i = 0 ; i < arr.length; i++){
console.log(arr[i]);
}
Explicit vs. Implicit coercion
var x = 42;
var explicit = String(x); // explicit === "42"
var implicit = x + "" ; // implicit === "42"
== vs. ===
== coerces the type
=== requires equivalent types
Coercion, cont.
^ did i put Object twice?
Nope,I put it 4 time
Everything else is an object
Prototypical Inheritance
var o = new Object();
o.firstname = "art";
o.lastname = "dvp";
o.isStudent = true;
o.age = 23;
o.greeting = function() { console.log("Hey"); };
console.log(JSON.stringify(o));
var o2 = {};
o2['firstname'] = "art";
var a = 'lastname';
o2[a] = 'DVP';
var o3 = {
firstName : "ART",
lastName : "DvP",
greet : function(){
console.log('hi');
},
address : {
street : 'Main st.',
number : '111'
}
};
Non-primitive types have a few properties/method associated with them
Array.prototype.push()
String.prototype.toUpperCase()
Each object stores a reference to its prototype
Properties/methods defined most tightly to the instance have priority
Most primitive types have object wrappers
String()
Number()
Boolean()
Object()
(Symbol())
JS will automatically "box" (wrap) primitive values so you have access to methods
42.toString() //Error
var x = 42;
x.toString() // "42"
x.__proto__ // [Number : 0]
x instanceof Number // false
var xx = new Number(32);
greeting();
doesThisWork();
function doesThisWork(){
console.log('pls');
}
function greeting(){
console.log('Hi');
}
The Javascript Engine
console.log(i);
greeting();
var i = 42;
function greeting(){
console.log('Hi');
}
var i
var x = 50;
function test(){
var x = 42;
function printX(){
console.log(x);
}
}