<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript"> /*
* 运算符也叫操作符
* 通过运算符可以对一个或多个值进行运算,并获取运算结果
* 比如:typeof就是运算符,可以来获得一个值的类型,它会将该值的类型以字符串的形式返回 number string boolean undefined object
*
* 算数运算符
* 当对非Number类型的值进行运算时,会将这些值转换为Number然后再运算,任何值和NaN做运算都得NaN
*
*
* + +可以对两个值进行加法运算,并将结果返回
* 如果对两个字符串进行加法运算,则会做拼串,会将两个字符串拼接为一个字符串,并返回
* 任何的值和字符串做加法运算,都会先转换为字符串,然后再和字符串做拼串的操作
*
* - - 可以对两个值进行减法运算,并将结果返回
*
*
* * * 可以对两个值进行乘法运算
*
* / / 可以对两个值进行除法运算
*
* % % 取模运算(取余数)
*/ var a = 123;
var result = typeof a;
console.log(result);//number
console.log(typeof result); //string result = a + 1;
console.log(result);//124 result = 456 + 789;
console.log(result);//1245 result = true + 1;
console.log(result);//2 //任何的值和字符串做加法运算,都会先转换为字符串,然后再和字符串做拼串的操作
result = true + false;
console.log(result);//1 //任何的值和字符串做加法运算,都会先转换为字符串,然后再和字符串做拼串的操作
result = 2 + null;
console.log(result);//2 //任何值和NaN做运算都得NaN
result = 2 + NaN;
console.log(result);//NaN //如果对两个字符串进行加法运算,则会做拼串,会将两个字符串拼接为一个字符串,并返回
result = "123" + "456";
console.log(result);//123456 result = "你好" + "大帅哥";
console.log(result);//你好大帅哥 var str = "锄禾日当午," +
"汗滴禾下土," +
"谁知盘中餐," +
"粒粒皆辛苦";
console.log(str);//锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦 //----------------------------------------------------------------------------------- //任何的值和字符串做加法运算,都会先转换为字符串,然后再和字符串做拼串的操作
result = 123 + "1";
console.log(result);//1231 //任何的值和字符串做加法运算,都会先转换为字符串,然后再和字符串做拼串的操作
result = true + "hello";
console.log(result);//truehello /*
* 我们可以利用这一特点,来将一个任意的数据类型转换为String
* 我们只需要为任意的数据类型 + 一个 "" 即可将其转换为String
* 这是一种隐式的类型转换,由浏览器自动完成,实际上它也是调用String()函数
*/
var c = 123;
c = c + ""; //和c = String(c)本质上是一样的
console.log(typeof c);//string result = 1 + 2 + "3";
console.log(result); //33 result = "1" + 2 + 3;
console.log(result); //123 //----------------------------------------------------------------------------------- result = 100 - 5;
console.log(result); //95 result = 100 - true;
console.log(result); //99 result = 100 - "1";
console.log(result); //99 result = 2 * 2;
console.log(result); //4 result = 2 * "8";
console.log(result); //16 result = 2 * undefined;
console.log(result); //NaN result = 2 * null;
console.log(result); //0 result = 4 / 2;
console.log(result); //2 result = 3 / 2;
console.log(result); //1.5 //----------------------------------------------------------------------------------- /*
* 任何值做 - * / 运算时都会自动转换为Number
* 我们可以利用这一特点做隐式的类型转换
* 可以通过为一个值 -0 、*1 、 /1来将其转换为Number,原理和Number()函数一样,使用起来更加简单
*/ var d = "123";
d = d - 0;
console.log(d); //123
console.log(typeof d);//number result = 9 % 3;
console.log(result); //0 result = 9 % 4;
console.log(result); //1 result = 9 % 5;
console.log(result); //4 </script>
</head>
<body>
</body>
</html>

JS基础_算数运算符的更多相关文章

  1. JS基础_相等运算符

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. JS基础_关系运算符

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. JS基础6--逻辑运算符

     &&与  ||或   !非      如果对一个值进行两次取反,它不会变化      如果对一个非布尔值进行取反,则会将其转换为布尔值,再取反      所以我们可以利用该特点.来将 ...

  4. JS基础_运算符的优先级

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. JavaScript基础一(js基础函数与运算符)

    [使用js的三种方式] 1.在HTML标签中,直接内嵌js(并不提倡使用) <button onclick=" alert('点就点')"> 点我啊</butto ...

  6. JS基础_属性名和属性值

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. JS基础_数据类型-Number类型

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. JS基础_标识符

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. JS基础_全局作用域

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

随机推荐

  1. [转]Nginx配置信息详解

    序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作为HTTP服务器,也 ...

  2. 在React中修改antd的样式

    1.在Component的Radio中加个style={radioStyle}. <RadioGroup> <Radio style={radioStyle} value={}> ...

  3. Handle的特点

    handler可以分发Message对象和Runnable对象到主线程中, 每个Handler实例,都会绑定到创建他的线程中(一般是位于主线程), 也就是说Handler对象初始化后,就默认与对它初始 ...

  4. python之scrapy模块scrapy-redis使用

    1.redis的使用,自己可以多学习下,个人也是在学习 https://www.cnblogs.com/ywjfx/p/10262662.html官网可以自己搜索下. 2.下载安装scrapy-red ...

  5. nginx.conf 配置 (反向代理,负载均衡,fastdfs model)

    #user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log notice;#error_l ...

  6. mysql查看系统参数

    show global variables like ‘innodb_buffer_pool_size’: 查看buffer相关参数 show global variables like 'buffe ...

  7. Daily in Ipin

    Friday, October 23 1. [道高一尺,墙高一丈:互联网封锁是如何升级的] Monday, October 12 1. 晕死,忘了ubuntu的登录密码,鼓捣了半个小时,终于成功进入系 ...

  8. Django前期知识准备

    一. WEB应用 WEB应用程序是一种可以通过WEB访问的应用程序, 程序的最大好处是用户很容易访问应用程序, 用户只需要有浏览器即可, 不需要再安装其他软件. 应用程序有两种模式: C/S, B/S ...

  9. Chrome F12 谷歌开发者工具解析

    一.工具简单介绍 F12可用于网站界面.性能测试,bug定位等 以 www.baidu.com 为例: Elements:查看页面元素属性(多用于自动化元素定位) Console:记录日志信息(用于定 ...

  10. Django:(02)项目配置

    上一篇我们创建了一个Django项目,并且让它运行了起来了. 当是,我们还没有使用到我们创建的应用,以及templates模版目录. 需求: 在此之前我们根据需要对我们的项目进行配置修改. 在项目开发 ...