如何在javascript中连接两个数字? [英] How to concatenate two numbers in javascript?

查看:53
本文介绍了如何在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中连接两个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆