Home >Web Front-end >JS Tutorial >Take you to understand JavaScript variable types and conversion between variables
This article brings you relevant knowledge about javascript. It mainly introduces JavaScript variable types and conversions between variables in detail. The sample code in the article is introduced in great detail and has certain Reference value, I hope it will be helpful to everyone.
[Related recommendations: javascript video tutorial, web front-end】
<script> var num =10; console.log(typeof num); </script>
typeof
: Declaration of variable type
##alert: Pop-up alert box
prompt: Input and output statements
true false)
undefined null
number.toString(radix)Parameter Descriptionradix Optional. Specifies the base of the number, which is an integer between 2 and 36. If this parameter is omitted, base 10 is used. Note, however, that the ECMAScript standard allows implementations to return any value if the parameter is a value other than 10.
var num=10; var str=num.toString(); console.log(str);
parseInt(string, radix)The example is as follows
var age=prompt('请输入您的年龄'); console .log(parseInt(age)); console.log(parseInt('3.14')); //取整 3 console.log(parseInt('3.98')); //取整 3 console.log(parseInt('120px')); //取整 120
parseFloat(string)The example is as follows
console.log(parseFloat('3.14')); console.log(parseFloat('120px')); //120会去掉px单位
var str='123'; console.log(number(str); console.log(number('123'));
console.log('12'-0); //12 console.log('123'-'120'); //3 console.log('123'*1); //123
var myBoolean=new Boolean();If the Boolean object has no initial value or its value is:
console.log(boolean(''));//false console.log(boolean(0));//false console.log(boolean(NaN));//false console.log(boolean(null));//false console.log(boolean(undefined));//falseThe rest are true. 【Related recommendations:
javascript video tutorial, web front-end】
The above is the detailed content of Take you to understand JavaScript variable types and conversion between variables. For more information, please follow other related articles on the PHP Chinese website!