Page 1 of 1

[DOC] Tricks Javascript, maybe toint not needed?

Posted: 27 March 2013, 22:37
by Rudolf
Hello;
I saw in BGA doc, the javascript trick 'toint(i) to avoid against 'string' compiler undrestanding...
I would like to add this trick (i think it's less complicate) :)

Code: Select all

var i=1, j=1;
	alert ("1+1="+i+j);  /* displays 11 */
	alert ("1+1="+(i+j)); /* displays 2 */ 
no need to use toint()?

Re: [DOC] Tricks Javascript, maybe toint not needed?

Posted: 28 March 2013, 16:48
by sourisdudesert
Hello,

Of course you can use this method too. The idea of "toint" is to make it explicit so you can't have some doubts. There are also situation (ex: comparisons) where the parenthesis method does not work.

Cheers,