补上今日学习所获

/*
运算符也叫操作符

通过运算符可以对一个或多个值进行运算,并获取运算结果
比如:typeof就是运算符,可以来获得一个值的类型
它会将该值的类型以字符串的形式返回----number、string、boolean、undefined、object
-----------IJ操作
var a = 123;
var result = typeof a ----(将运算结果保存在变量里面)typeof a 返回的结果就是变量类型
-----------控制台操作
console.log(result)
等于=== console.log(typeof a) --直接输出为保存
typeof的返回值是一个字符串,字符串的作用是用来描述一个类型的
/*算数运算符
+
+可以对两个值进行加法运算,并将结果返回
var a = 123;
a + 1;
console.log(a)
显示:"123"----不会对原变量产生影响
var a = 123;
result = a + 1;-----------可以改为:a =a + 1;
console.log(result)------------- console.log(result)
显示:"124"------------------------ 显示:"124"
当对非Number类型的值进行运算时,会将这些值转换为Number然后在计算。如下://注意:除字符串的加法!
result = true + 1;
显示:2
result = true + false;
显示:1
result = 2 + null;
显示:2
result = 2 + NaN;
显示:NaN--------任何值和NaN做运算都得NaN
result = “123”+“456"
显示:"123456"
//如果对两个字符串进行+法运算,则会将两个字符串拼接为一个字符串,并返回--------type是string
双引号必须在同一行,加号+可以把一句如古诗词拼接到一行
//注意任何的值和字符串做加法运算,都会转换为字符串,然后再和字符串做拼串的操作
result = 123 + ”1“;
显示:"1231"
result = true+ ”hello“;
显示:"truehello"
任意的数据类型+一个“ ”可以转化为String-------这是一种隐式的类型转换,由浏览器自动完成,实际上,它也是调用的String函数
var c = 123;
c = c + " "
显示”123“
直接写console。log("C = ”+C)
显示”C = 123“
练习:
result = 1 + 2 + ”3“;//123 33--------1+2=3于”3“拼串
console。log(”result = “+result);
显示:“result = 33”
result = ”1“ + 2 + 3;-------//”1“于2拼串再与3拼串,显”123“
/*2、减号- 两个值进行减法运算,并将结果返回. 减号都转为Number
result = 100 - 5;
显示:"99"
result = 100 - true;
显示:"99"
result = 100 - ”1“;
显示”99“--------把"1"字符串"1"转为1了
/*3、星号✳ 可以对两个值进行乘法运算
/ 可以对两个值进行除法运算
result = 2 * 2;
console。log(”result = “+result);
显示:"result = 4"
result = 2 * "8"; ---转成Number乘以8
console。log(”result = “+result);
显示:"result = 16"
result = 2 * undefined;
显示“NaN"
result = 2 * null;
显示:”0“
result = 4 / 2;
显示:”2“
result = 3 / 2;
显示:”1.5“
任何值做- * /运算时都会自动转换为Number,可以利用这一特性进行类型转换 -0,*1,/1将其转化为Number.和number()函数一样
var d = "123"-------------------------+d = number(d),转为“number”或者是d = d - 0;-值不变的情况下,类型转化为number
console.log(typeof d);
console.log(d);
显示:”string“
”123"
/4、取余数%
result = 9 % 3;
console。log(”result = “+result);
显示:" result = 0"
result = 9 % 4;
显示:" result = 1"
result = 9 % 5;
显示:" result = 4"
*/
posted @   LiLime  阅读(20)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示