Where to use Number() and parseInt() in Javascript?
Number(object) tries to convert the entire string to a number(which can also be a float) while parseInt(object) parses up to first non-digit and returns whatever value has been parsed.
So, if you have "1234@gmail.com" and you want to get 1234 out of it, then use parseInt("1234@gmail.com");
But, if you have "1234" and you want to convert the entire string as one number then use Number("1234");
Number(object) tries to convert the entire string to a number(which can also be a float) while parseInt(object) parses up to first non-digit and returns whatever value has been parsed.
So, if you have "1234@gmail.com" and you want to get 1234 out of it, then use parseInt("1234@gmail.com");
But, if you have "1234" and you want to convert the entire string as one number then use Number("1234");
Comments
Post a Comment