This article introduces you to the usage examples of the six data types of JavaScript. For knowledge about JavaScript, you can search for relevant content on PHP中文网.
Related recommendations: http://www.php.cn/code/793.html
1 Numeric type
Numeric type includes: integer type, float, NaN.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //现在我们想让一个东西的长度变成原来的10倍 var length = "300m"; /* 一个字符串,是不能转换成有意义的数值的,只能转换成NaN 一个含纯数字的字符串,可以转成有意义的数值,大家可以修改length为纯数字的字符串,输出查看结果 */ length = length*10; document.write(length); </script> </head> <body> </body> </html>
2.Character type
A string enclosed by single or double quotes
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> var name = "小明"; //加号为字符串连接符,我们之后会介绍 var str = "我的名字叫做'" +name+"'" document.write(str) </script> </head> <body> </body> </html>
3.Boolean type
Boolean type is also Called logical type. There are only two values: true (true), false (false).
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> var x = 10; var y = 110; //x>y比较出来的结果是布尔值 if(x>y){ document.write(x+"比"+y+"大些"); }else{ document.write(y+"比"+x+"大些"); } </script> </head> <body> </body> </html>
4. Escape character
The meaning character is backslash (\).
Commonly used escape characters include: \', \”, \\, \r, \n, etc.
That is, when the browser encounters a backslash (\) , the following character will be treated specially and treated as a normal character. The so-called "normal" characters are a, b, c, &, etc. 5. Null value
##. #When an object does not exist, the empty type will be returned. The value of the empty type is only null.<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> var name = "小明"; //加号为字符串连接符,我们之后会介绍 var str = "我的名字叫做\"" +name+"\"" document.write(str) </script> </head> <body> </body> </html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> var x = null; document.write(x); </script> </head> <body> </body> </html>
The above is the detailed content of Introduction to JavaScript data types. For more information, please follow other related articles on the PHP Chinese website!