JavaScript 比较和逻辑运算符
2013-12-09 11:24
323 查看
比较运算符
比较运算符在逻辑语句中使用,以测定变量或值是否相等。运算符 | 描述 | 例子 |
---|---|---|
== | 等于 | x==8 为 false |
=== | 全等(值和类型) | x===5 为 true;x==="5" 为 false |
!= | 不等于 | x!=8 为 true |
> | 大于 | x>8 为 false |
< | 小于 | x<8 为 true |
>= | 大于或等于 | x>=8 为 false |
<= | 小于或等于 | x<=8 为 true |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <script> var age=22; if (age<18){ document.write("Too young"); }else{ document.write("too old"); } </sipt> </body> </html>
逻辑运算符
逻辑运算符用于测定变量或值之间的逻辑。给定 x=6 以及 y=3,下表解释了逻辑运算符:
运算符 | 描述 | 例子 |
---|---|---|
&& | and | (x < 10 && y > 1) 为 true |
|| | or | (x==5 || y==5) 为 false |
! | not | !(x==y) 为 true |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <script> var x = 2; if(x<10 && x>1){ document.write("true"); }else{ document.write("false"); } </script> </body> </html>
相关文章推荐
- [置顶] Extjs4 异步刷新书的情况下 保持树的展开状态
- JSON javaScript中的用法
- Javascript基础form表单
- javascript(js)中使用this
- Kohana框架as_array转换json数据
- JS判断浏览器是否为IE(__proto__)
- chrome 控制台js调试与断点调试
- Ajax跨域请求与jsonp
- flash as 与js通信
- 【转载】Chrome 中的 JavaScript 断点设置和调试技巧
- Chrome 调试JS利器
- ctags: Warning: ignoring null tag in .\\st_plugins\\editor\\ckeditor\\ckeditor.js
- 帝国CMS调用生成JS,自定义JS
- js提交表单kindeditor编辑器textarea为空解决办法
- JS间隔向上翻动-左右滚动
- JS随机颜色标签云
- JavaScript跨域
- ajax跨域和js跨域解决方案(转)
- JavaScript 运算符
- javascript在控制在返回页面加载后重新强制刷新一次