Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva
 

Some useful Javascript Snippets 

 

Some useful Javascript Snippets 

 

Test Var Undefined and default argument

Test Var Undefined and default value for argument

if (typeof variable ==='undefined') {
   // your code
}
//  the following function has the last 2 arguments nont mandatory
function bymanHeightEqual(pElementMain, pElementCompare, pHeight, pHeightPlus ) {

// default value for arguments not mandatory
pHeight=pHeight || "higher";
pHeightPlus=pHeightPlus || 0 ;

 

URL Contains

Search in the URL

// Search in the url
if(location.href.indexOf('/en/')>-1){
  $("body").addClass("enClass");
}

 

How Many Days in the Month

Days in a month

function getDaysInMonth(m, y){return/8|3|5|10/.test(--m)?30:m==1?(!(y%4)&&y%100)||!(y%400)?29:28:31;}

 

URL Address Null

 

URL like #

// url will be more or less like #....no effect
javascript:void(0)

 

Define an Object

 

Define an Object

// simple object
var myObject={};
myObject["name"]="pippo";
myObject["age"]="77";
console.log(myObject.name);

  

To Be continued

To Be Continued... 

Stay tuned, I will add more snippets soon...

 

DISQUS - Leave your comments here