本文介绍了如何在javascript中连接两个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望像 5 + 6 这样的东西返回56而不是 11

I'd like for something like 5 + 6 to return "56" instead of 11.

推荐答案

使用+ 5 + 6 强制它为字符串。这也适用于数值变量:

Use "" + 5 + 6 to force it to strings. This works with numerical variables too:

var a = 5;
var b = 6;
console.log("" + a + b);

这篇关于如何在javascript中连接两个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:46