Why are ES6 template strings the way they are? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
What are the reasons that we have to use:
` instead of ', and
${var} instead of $var (like e.g. in Kotlin)

backwards compatibility: you don't want existing programs using single quoted strings to suddenly behave differently because they are now interpreted as template strings.
Too often a dollar sign may need to be literal. To avoid that you would have to escape it often, ${ } is prescribed: it is a less recurring pattern you would want to produce literally in strings.

Related

why ` is different than ' in JavaScript? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I started learning JavaScript, and I have faced this problem with strings.
the problem is
and the result is
Why are the results different?
`` - this is 'backtick' - when you use those characters, this is template string. This syntax allows you, to use for example, multiline strings or nested js variables ${}.
'' or "" - this is standard js syntax for strings, you cannot use here ${}

Should we start enclosing strings consistently using back ticks (`)? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am learning ES6. Just realized that using back ticks (`) to enclose string values has many benefits - and I am also sure it is little slower compare to simple string concatenation.
However, given the browser optimizations and advancement, is it safe to make it a general practice to enclose all strings using back ticks for consistency sake?
In other words, is it safe to establish it as a best practice to enclose string values with back ticks.
Back ticks are for template strings, if there are no variables for interpolation in your string then stick to a single quote.

Only if contains >< /!a-zA-Z or some of them with regular expression [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to check string if contains >< /!a-zA-Z or some of them (Also contains space). The only thing I know is a-zA-Z i need an example in C# or Javascript.
Use a "character class".
/[>< \/!a-zA-Z]/
Note that I've escaped the forward slash, since we're using forward slashes as delimiters.

Regex test, is there a better way to write this? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
The following code works, but I wonder if there is a better way to achieve the same result:
var regex = /define\((\s+)?['|"](PRIVATE_KEY)['|"],(\s+)?['|"](.*)['|"](\s+)?\)/i;
Test:
regex.test("define('PRIVATE_KEY', 'MYSECRETKEY');");
https://regex101.com/r/pW0qS0/4
First I think you don't need to use pip within character class (if you want to match only one quote and double quote) also instead of (\s+)? you can use \s*:
/define\(\s*['"](PRIVATE_KEY)['"],\s*['"](.*)['"]\s*\)/i
See demo https://regex101.com/r/dL1vF4/3

Why String is immutable in JavaScript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it. However, it is still possible to create another string based on an operation on the original string
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
I understand what immutable mean, but i need to know why they built it like this and what the value of this immutable approach?
Note: I reviewed some Java reference but I'm not Java developer, and I can't understand there terms (StringPool, hashcode ...)

Categories