javascript - what's the use of having plus sign infront of an expression -
eq: function( ) {     var len = this.length,         j = +i + ( < 0 ? len : 0 );     return this.pushstack( j >= 0 && j < len ? [ this[j] ] : [] ); },   i'm new programming in general, purpose of having single + sign infront of expression, i've seen these in jquery library lot.
+(expression)   these i'd understand, negative:
-(1);// -1      
it converts string number actual number in expression.
console.log(typeof +"1");        // number console.log("1" + "1");          // 11 console.log(+"1" + +"1");        // 2 console.log("1.3" + "1.546");    // 1.31.546 console.log(+"1.3" + +"1.546");  // 2.846   quoting ecma 5.1 standard specifications + operator,
the unary + operator converts operand number type.
internally, javascript string converted number based on these rules specified in ecma 5.1 standards.
edit: per number specifications, internally uses same tonumber convert parameter number. so, technically number(<number string>) same +<number string>.
Comments
Post a Comment