博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javascript单引号_JavaScript中的引号
阅读量:2506 次
发布时间:2019-05-11

本文共 1458 字,大约阅读时间需要 4 分钟。

javascript单引号

JavaScript allows you to use 3 types of quotes:

JavaScript允许您使用3种引号:

  • single quotes

    单引号
  • double quotes

    双引号
  • backticks

    反引号

The first 2 are essentially the same:

前两个基本相同:

const test = 'test'const bike = "bike"

There’s little to no difference in using one or the other. The only difference lies in having to escape the quote character you use to delimit the string:

使用任何一个几乎没有差异。 唯一的区别在于必须转义用于定界字符串的引号字符:

const test = 'test'const test = 'te\'st'const test = 'te"st'const test = "te\"st"const test = "te'st"

There are various style guides that recommend always using one style vs the other.

有多种样式指南建议始终使用一种样式,而不是另一种样式。

I personally prefer single quotes all the time, and use double quotes only in HTML.

我个人更喜欢一直使用单引号,并且仅在HTML中使用双引号。

Backticks are a recent addition to JavaScript, since they were introduced with ES6 in 2015.

自2015年在ES6中引入反引号以来,反引号是JavaScript的最新成员。

They have a unique feature: they allow multiline strings.

它们具有独特的功能:它们允许多行字符串。

Multiline strings are also possible using regular strings, using escape characters:

多行字符串也可以使用常规字符串,并使用转义字符:

const multilineString = 'A string\non multiple lines'

Using backticks, you can avoid using an escape character:

使用反引号,可以避免使用转义符:

const multilineString = `A stringon multiple lines`

Not just that. You can interpolate variables using the ${} syntax:

不仅如此。 您可以使用${}语法插值变量:

const multilineString = `A stringon ${1+1} lines`

, that dives more into the nitty-gritty details.

将更深入地探讨细节。

翻译自:

javascript单引号

转载地址:http://jxqgb.baihongyu.com/

你可能感兴趣的文章
laravel 定时任务秒级执行
查看>>
浅析 Laravel 官方文档推荐的 Nginx 配置
查看>>
Swagger在Laravel项目中的使用
查看>>
Laravel 的生命周期
查看>>
CentOS Docker 安装
查看>>
Nginx
查看>>
Navicat远程连接云主机数据库
查看>>
Nginx配置文件nginx.conf中文详解(总结)
查看>>
MySQL innert join、left join、right join等理解
查看>>
sdc时序约束
查看>>
NoC片上网络
查看>>
开源SoC整理
查看>>
【2020-3-21】Mac安装Homebrew慢,解决办法
查看>>
influxdb 命令行输出时间为 yyyy-MM-dd HH:mm:ss(年月日时分秒)的方法
查看>>
已知子网掩码,确定ip地址范围
查看>>
判断时间或者数字是否连续
查看>>
docker-daemon.json各配置详解
查看>>
Docker(一)使用阿里云容器镜像服务
查看>>
Docker(三) 构建镜像
查看>>
FFmpeg 新旧版本编码 API 的区别
查看>>