JSFiddle - React, Tailwind, and code Playground
by Ishank Dubey
JavaScript
/*****************Wiered behavoiur when Floating numbers are invloved***************************/
var x = .3-.2;
var y = .2-.1;
//alert((x==y)+(' Floating Numbers Invloved'));
var x1= 1.3-.2;
var y1= 1.2-.1;
//alert(x1==y1);//Binary floating value problem- Solution is to Scale the floating numbers to integers.
/********************Basic Regex Syntax****************************************/
var one = /html/;
var aStr = 'isthishtml';//Read only Array- immutable
/*******************Boolean Values*************************/
var x;
if(x){
//alert('here');//Always Good to Exlipcitly compare with undefined or Null or any other Unwanted/Wanted value/object
//Remeber- undefined;null;NaN;0;-0;""; are all falsy values
}
var aTest = null;
if(aTest){
//alert("If");
}else{
//alert("Else");//Works as expected
}
var aTest1 = new Object(null);
if(aTest1){
//alert("Object Of Null");
}else{
//alert("Null out of Null");
}
//Note this-
if(aTest1==null){
//alert("null");
}
/************************ When to use the - new?- An Example *************/
var aBool = new Boolean(false);// Boolean(false) or false
aBool.prop = 'Saving Private Ryan'; // using new operator, without the- new, the property will not persist i.e aBool.prop will return undefined.
//alert("BOOL::::----"+(aBool.prop));
/******************************Assosiative Array behavoiur of a JS Object***********************/
var aVar = Object();
aVar["prop space"] = 'Black hawk Down';// Associative Array behavoiur of a JS Object.
//alert(aVar["prop space"]); // Can be helpful at times!!
/****************************TYPE Conversations**********************/
var aNow = new Date();
//alert(aNow-1+" -----");// '-' and '+' cause different behaviour on JS object valueOf() and then toString(); function calls
/********************************Repeated Declarations********************/
var aRepeat = 'Troy';
var aRepeat = "Gladiator";
//alert(aRepeat);// Repated declarations are ok, but its...