Comments (6)
I cannot find the issue in the live page.. am I missing anything?
from content.
Both issues are still present.
The first page (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) shows this example under the section "Raw strings":
let str = String.raw`Hi\n${2+3}!`;
// "Hi\n5!"
str.length;
// 6
Those 2 results contradict each other.
"Hi\n5!"
is a string of length 5.
Whereas the correct output should be:
> let str = String.raw`Hi\n${2+3}!`
undefined
> str.length
6
> str
'Hi\\n5!'
Furthermore, the second page (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) consistently refers to "template strings" in the text and the link at the bottom of the page. As the first page indicates, this is an obsolete term. The documentation should reflect the usage in the standard: template literals
from content.
Thanks for getting back @dsletten
There's a comment afterward that says: the character after 'Hi' // is not a newline character, // '\' and 'n' are two characters.
which explains why \n
shows up as 2 characters instead of 1. Indeed, if you wanted to create it yourself without String.raw, you would have to use \\n
to escape it but this is not the case here, so I don't think it makes sense to write the string escaped (considering that we have the explanation in comments). Does that make sense?
In the template strings page, instead of the comment, there's this code: Array.from(str).join(',');
which shows how it is indeed made up of 6 characters. Please let me know if I missed something.
As for the 2nd issue, can you tell me where you saw that the term "template string" is obsolete? I could not find that on the template literals page.
Thanks!
from content.
Evidently you are referring to the 2nd page: String.raw(). My observation refers to the first page: Template literals. The example shows this result as a literal String:
let str = String.raw`Hi\n${2+3}!`;
// "Hi\n5!"
In JavaScript, that literal value represents a 5-character string. The backslash must be escaped to show that it is a literal '\' and not a newline '\n'.
With regard to the 2nd issue, the "Template literals" reference page opens with this statement:
They were called "template strings" in prior editions of the ES2015 specification.
If the language specification no longer uses the term "template strings", then ideally the MDN documentation should reflect this.
from content.
Thanks @dsletten, I've opened a PR to change template strings to template literals. I did leave out .templateString
the specification still refers to templateString inside template strings
Regarding the first issue, I will leave it for someone else, as I get your point but considering the clarification under it I think it makes sense. However, I could be wrong so I will leave it for someone else to take a look at
from content.
I’ve opened #5903 with a fix for code examples
from content.
Related Issues (20)
- [WebAPI] Implement IDBTransaction durability option HOT 2
- RTCIceCandidate: relatedAddress Examples section error HOT 2
- document of RTCIceCandidate's properties { url, relayProtocol} are missing HOT 1
- [spam]
- Default `step` value for `datetime-local` input is incorrect
- [Web API] Expose effective zoom
- There is no 'instant' option in 'behavior' HOT 2
- missing internationalization information
- The transform-origin attribute of a svg element only works with px or without unit
- offsetParent affected by transform, filter, etc
- autocapitalize=off is considered deprecated by wpt
- starting code for task5 is incomplete HOT 1
- Express Tutorial Part 4: Routes and Controllers - Add a word to the sentence. HOT 1
- Client_hints page not found vary the response
- Use ::after to including icons on links HOT 1
- Accessibility advice is misleading
- Log out only working for superuser, other users throw "Django administration" authorization error on logout HOT 4
- (Spam)
- Does bzip compression relate to the `Accept-Patch` header? HOT 1
- <hgroup> tag is deprecated in HTML5 specifications, but it is not included in "Obsolete and deprecated elements" in the page HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from content.