SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Sunday, February 8, 2015

Sunday, November 2, 2014

Javascript : You might also like - I

Javascript hoisting

  1. http://jamesallardice.com/explaining-function-and-variable-hoisting-in-javascript/
  2. http://blog.caplin.com/2012/01/18/javascript-is-hard-part-2-the-hidden-world-of-hoisting/
  3. http://code.tutsplus.com/tutorials/the-essentials-of-writing-high-quality-javascript--net-15145
  4. http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html

What's the difference b/w the two declaration methods below ?

var functionOne = function() {
    /* some code */
}
function functionTwo() {
    /* some code */
}
functionOne is defined in-place(until that line, functionOne is undefined),
whereas functionTwo is hoisted to the top of the scope and is available
as function throughtout the scope. 

Logical Q's

  1. true + true  returns 2
  2. Math.min() < Math.max(); will return false

Friday, October 31, 2014

Things you may not know about Javascript

Object Literal provide a very convenient notation for creating new object values. An object literal is a pair of curly braces surrounding zero or more name/value pairs.

var empty_obj={};
var stooage={"firstname":"Gen","lastname":"Linux"}

Objects can nest.

var flight={
      air:"BA",number:"335",departure:{Gate:"45"}
}

Undefined value is produced if an attempt is made to retrieve a non-existent member.

stooage.status     // undefined
flight["area]        // undefined

Attempting to retrieve values from undefined will throw a TypeError exception.

flight.equipment         // undefined
flight.equipment.model      // throw "TypeError"

This can be guarded against with the && operator:

flight.equipment && flight.equipment.model       // undefined


Reference

Objects are passed around by reference. They are never copied:

var x=stooge;
x.nickname = 'Curly';
var nick = stooge.nickname;
// nick is 'Curly' because x and stooge

// are references to the same object

Function Literal

Function objects are created with function literals:

// Create a variable called add and store a function
var add = function (a, b) {
return a + b;

};