Nodejs String to Number Convert toNum()

Here you can find the source of toNum()

Method Source Code

String.prototype.toNum = function() {
   if (this.length === 0) return 0;
   return parseInt(this);
}

Related

  1. toNumber()
    String.prototype.toNumber = function() {
        return parseInt(this);
    };
    var ten = "10";
    var fifty = "50";
    console.log(ten.toNumber()); 
    console.log(fifty.toNumber()); 
    
  2. toNumber()
    String.prototype.toNumber = function() {
      return parseFloat(this);
    };
    
  3. toNumber()
    String.prototype.toNumber = function(){
      return +this;
    };
    
  4. toNumber()
    String.prototype.toNumber = function(){
      if(this.match(/\./)){
        return parseFloat(this, 10);
      } else {
        return parseInt(this, 10);
    };