Javascript Global Functions
From Yate Documentation
				
								
				(Difference between revisions)
				
																
				
				
								
				| (One intermediate revision by one user not shown) | |||
| Line 3: | Line 3: | ||
| * <div id="isNaN">'''isNan(arg)'''</div> | * <div id="isNaN">'''isNan(arg)'''</div> | ||
| This function checks if ''arg'' is a number or not. | This function checks if ''arg'' is a number or not. | ||
| + | |||
| + | Returns true if ''arg'' is not a number, false if it's a valid number. | ||
| + | |||
| + |  Engine.output(isNaN(null)) | ||
| + | |||
| + |  '''true''' | ||
| * <div id="parseInt">'''parseInt(str)'''</div> | * <div id="parseInt">'''parseInt(str)'''</div> | ||
| − | Converts a string ''str'' to a number using  | + | Converts a string ''str'' to a number using the default numbering base 10. | 
| Obeys usual programming conventions: | Obeys usual programming conventions: | ||
| Line 12: | Line 18: | ||
| * All other strings are assumed decimal | * All other strings are assumed decimal | ||
| − | Returns number or  | + | Returns a number or '''NaN''' if ''str'' was not parsable. | 
| + | |||
| + |  x=parseInt("0x1234"); | ||
| + |  Engine.output((typeof x) + " " + x); | ||
| + | |||
| + |  '''number 4660''' | ||
| * <div id="parseInt">'''parseInt(str,base)'''</div> | * <div id="parseInt">'''parseInt(str,base)'''</div> | ||
| − | Converts a string ''str'' to a number using a specific numbering ''base'' | + | Converts a string ''str'' to a number using a specific numbering ''base''. | 
| Base must be between 2 and 36. | Base must be between 2 and 36. | ||
| + | |||
| + | Returns a number or '''NaN''' if ''str'' was not parsable in numbering ''base''. | ||
| + | |||
| + |  x=parseInt("12z",36); | ||
| + |  Engine.output((typeof x) + " " + x); | ||
| + | |||
| + |  '''number 1403''' | ||
Latest revision as of 15:21, 11 September 2013
These functions exist in the global context and can be called from anywhere.
-  isNan(arg)
This function checks if arg is a number or not.
Returns true if arg is not a number, false if it's a valid number.
Engine.output(isNaN(null)) true
-  parseInt(str)
Converts a string str to a number using the default numbering base 10.
Obeys usual programming conventions:
- Strings starting with 0x are hexadecimal
- Strings starting with 0 are octal
- All other strings are assumed decimal
Returns a number or NaN if str was not parsable.
x=parseInt("0x1234");
Engine.output((typeof x) + " " + x);
number 4660
-  parseInt(str,base)
Converts a string str to a number using a specific numbering base.
Base must be between 2 and 36.
Returns a number or NaN if str was not parsable in numbering base.
x=parseInt("12z",36);
Engine.output((typeof x) + " " + x);
number 1403
