javascript语言结构小记(一)
时间:2024-05-08 09:39:42
一:js支持 Unicode 字符集,所以可以用中文命名函数。
二:js 在Var中没有初始化的变量,默认为undefined
三:对于未声明也未赋值的变量,如果直接使用,会抛出一个系统级别的Error,如果用typeof(typeof是种类型运算符)操作来说,不论是否已经被声明,都将返回一个字符串”undefined”;
例:
//a 未声明
alert(typeof(a));//undefined
alert(a);//Error
四:算术运算符。用“+”可以较方便地将一个数值转换成字符串,具体操作是将操作是将这个数值加上一个空串(也可不写)。
例:
Var a=2.96;
Var b=1.0;
Alert(a+””+b);//得到字符串”2.961”
用“-“可用来将字符串装换成数值,具体操作是将这个字符串减去一个数值 0
Var a=”2.96”;
alert(a+1);//得到字符串”2.961”(将数值强制转换成字符串)
alert(a-0+1);//得到数值3.96
以下是我做的一个example:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js</title>
<script language="javascript">
x=5+5;
document.write(x+"<br>");
x="5"+"1";
document.write(x+"<br>");
x="5"+5;
document.write(x+"<br>");
x="10"-5;
document.write(x+"<br>");
</script>
</head>
<body>
</body>
</html>
结果:
10
51
55
5
标签:语言结构
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决python中画图时x,y轴名称出现中文乱码的问题
2023-08-04 09:00:23
![](https://img.aspxhome.com/file/2023/2/92402_0s.jpg)
如何使用python操作vmware
2023-03-13 17:34:41
Python用requests-html爬取网页的实现
2023-03-21 13:24:14
python基于exchange函数发送邮件过程详解
2021-03-23 02:12:22
![](https://img.aspxhome.com/file/2023/7/96907_0s.png)
基于Python闭包及其作用域详解
2023-11-07 07:22:02
![](https://img.aspxhome.com/file/2023/9/90839_0s.jpg)
JQuery对ASP.NET MVC数据进行更新删除
2024-06-05 09:32:05
![](https://img.aspxhome.com/file/2023/4/122784_0s.png)
Pytest框架 conftest.py文件的使用详解
2023-06-20 08:16:52
了解一下python内建模块collections
2022-03-19 08:32:37
Windows下的Python 3.6.1的下载与安装图文详解(适合32位和64位)
2021-06-28 16:02:24
![](https://img.aspxhome.com/file/2023/6/125046_0s.png)
Python基于回溯法子集树模板实现8皇后问题
2023-09-25 08:34:45
![](https://img.aspxhome.com/file/2023/4/104884_0s.jpg)
MAC 中mysql密码忘记解决办法
2024-01-18 04:13:48
Pygame游戏开发之太空射击实战盾牌篇
2023-09-20 22:47:59
SQL 随机查询 包括(sqlserver,mysql,access等)
2024-01-26 15:42:43
教你用Python pygame设置窗口标题和图标
2023-01-21 08:04:22
![](https://img.aspxhome.com/file/2023/0/133370_0s.png)
Python列表元素删除和remove()方法详解
2023-04-07 08:48:54
![](https://img.aspxhome.com/file/2023/3/127143_0s.png)
python编程Flask框架简单使用教程
2023-12-25 20:23:33
django 前端页面如何实现显示前N条数据
2023-06-07 10:50:33
开启MySQL的binlog日志的方法步骤
2024-01-29 07:31:25
![](https://img.aspxhome.com/file/2023/3/105483_0s.png)
PHP PDOStatement::setAttribute讲解
2023-06-04 02:48:47
PyQt5 QThread倒计时功能的实现代码
2021-08-02 06:00:28