Tuesday, December 25, 2012

Convert Int to string

Importance of +""

We all are aware of string to Int conversion,(which could be accomplished by parseInt) but how do we convert a Int to string? We do have multiple solutions but one of the most easiest and commonly used procedure is +"".

Below example illustrates the same.

var x=Math.random(); // this generates random number and type of x is number.
var x=Math.random()+""; // now check the type of x its string!!!! how is that possible.

Note: Just by using +"" it converts the type from number to string. This implementation is mostly used in displaying date. It helps to CONCAT the date, month or year value instead of adding them.

Hope this post was helpful. Will be adding some more post shortly.

Informative Javascript

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me..I am a regular follower of your blog.
    Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from HTML5 CSS3 Javascript Online Training from India .
    or learn thru HTML5 CSS3 Javascript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. HTML5 CSS3 Javascript Online Training from India