Javascript Number isPositive()

Description

Javascript Number isPositive()


Number.prototype.isPositive = function() {
  return this > 0;
}

var n = new Number(3);
console.log(n.isPositive());//ww  w . j  a  v a 2  s . co m

Javascript Number isPositive()

Number.prototype.isPositive = function() {
    return this > 0;
}
var a = new Number(-4);
console.log(a.isPositive());/*from   ww  w .j av a 2s.c om*/

Javascript Number isPositive()

Number.prototype.isPositive = function() {
    return this > 0;   
}

3.isPostive(3); // will return an error, even though a string might work in something similar, but
a.isPositive() // would work

Javascript Number isPositive()

Number.prototype.isPositive = function(){
 return this > 0;
}
var a = new Number(3);
console.log(a.isPositive());// w  w  w  . j a  v  a 2 s .co  m

var a = 3; // primitive
var b = new Number(3); // object created by function constructor.
console.log(a==b);
console.log(From:git source
===b);

var d = new Date()

Javascript Number isPositive()

Number.prototype.isPositive = function() {
    return this > 0;   
}

Javascript Number isPositive()

Number.prototype.isPositive = function() {
  return this > 0;
}

// 3 is not a Number Object.

//console.log(3.isPositive());   // cause error

//console.log("3".isPositive());  // also cause error

var a = new Number(4);

//here a is Number Object

console.log(a.isPositive());    // true



PreviousNext

Related