js中“=”和“==”都表示什么意思啊例1:var now = new Date();var day = now.getDay();var dayName;if (day == 0) dayName = "星期日";else if (day == 1) dayName = "星期一";else if (day == 2) dayName = "星期二"; else if (day == 3) da
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 21:27:34
js中“=”和“==”都表示什么意思啊例1:var now = new Date();var day = now.getDay();var dayName;if (day == 0) dayName = "星期日";else if (day == 1) dayName = "星期一";else if (day == 2) dayName = "星期二"; else if (day == 3) da
js中“=”和“==”都表示什么意思啊
例1:
var now = new Date();
var day = now.getDay();
var dayName;
if (day == 0) dayName = "星期日";
else if (day == 1) dayName = "星期一";
else if (day == 2) dayName = "星期二";
else if (day == 3) dayName = "星期三";
else if (day == 4) dayName = "星期四";
else if (day == 5) dayName = "星期五";
else dayName = "星期六";
document.write ("今天是快乐的",dayName);
例2:
var now = new Date();
var day = now.getDay();
var dayName;
if (day = 0) dayName = "星期日";
else if (day = 1) dayName = "星期一";
else if (day = 2) dayName = "星期二";
else if (day = 3) dayName = "星期三";
else if (day = 4) dayName = "星期四";
else if (day = 5) dayName = "星期五";
else dayName = "星期六";
document.write ("今天是快乐的",dayName);
结果为什么不一样啊
js中“=”和“==”都表示什么意思啊例1:var now = new Date();var day = now.getDay();var dayName;if (day == 0) dayName = "星期日";else if (day == 1) dayName = "星期一";else if (day == 2) dayName = "星期二"; else if (day == 3) da
“=”是赋值操作符.
“==”是判断值是否相等操作符.
“===”是判断是否完全相等操作符.
举个例子:
x=8;//表示把8赋值给x
x==y;//判断x和y是否相等,在这里,如果x=“55”;y=55,前者是一个字符串,后者是一个数值,但是按照js规范,x==y也是成立的,也就是说他们是相等的.
x===y;//判断x和y是否完全相等,如果=“55”;y=55,前者是一个字符串,后者是一个数值,但是按照js规范,x==y就是不成立的,因为类型不同.