Javascript String isGreaterThan(limit)

Description

Javascript String isGreaterThan(limit)


String.prototype.isGreaterThan = function(limit) {
  return this.length > limit;
}

console.log("Ivan".isGreaterThan(3));
console.log("Ivan".isGreaterThan(5));

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

/*/*ww  w.ja  v  a 2 s. c  o  m*/
* Buit in Function Constructor can be dangerous
* for primivite types: String, Number, etc.
*/
var a = 3; // primivite

var b = new Number(3); // object created with function constructor

a == b; // it converts to same type (coercion) and is true
a === b; // not the same type is false.

Javascript String isGreaterThan(limit)

//adding new/*from   w ww . j  a  v  a 2s  . c om*/

String.prototype.isGreaterThan = function(limit) {
  return this.length > limit;
}

console.log("Shamit".isGreaterThan(3));  // true

// "shamit" is a string object



PreviousNext

Related