javascript - Why does using parseInt on Error return 14? -


consider following:

parseint(new array(), 10); // -> nan parseint(new array(), 16); // -> nan  parseint(new error(), 10); // -> nan parseint(new error(), 16); // -> 14 

it seems behavior unique error/instances of error. can provide insight?

basically, that's because:

  • new error().tostring() yields "error", and
  • parseint("error", 16) yields 14 (because 0xe 14 , parser stops @ r).

on other hand, new array() not trigger same behavior because tostring() method of array objects returns contents of array, delimited commas, not class name. therefore, new array().tostring() yields empty string, , parseint() subsequently yields nan.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -