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.
Related
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 ${}
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
I created a webshop for an online game where the users can buy in-game stuff. I have some special items which will be only availabe for a short period of time and I want to print out how much time left to buy it.
I wrote a JS code to countdown for a date, and now I want to store it in the database. Which is the best way to do it? Just a varchart with extremely long length? Or is it a more elegant way to deal with this?
You can use Function.prototype.toString method to convert a function into a string and then later use eval to execute the function.
You should use text type rather than varchar as it will likely be longer than maximum varchar length.
However, I would strongly discourage you to do this. A better approach would be to store something like a expiration date timestamp and calculate the availability based on that value.
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.
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 6 years ago.
Improve this question
How many spaces should be used for each line of if statement at the beginning of the line?
suppose we have 10 lines of nested if statements, what is the formula to determine how many lines to be used? Also can a programmer use the tab key instead to obtain proper indentation for a statement.
if (a !== 0) {
if (b > 1) {
if (c < 1) {
Indentations and spaces is not a requirement it just helps your code to be more readable.
Unlike languages like Python in which whitespace is considered semantic by the compiler, the Javascript compiler ignores runs of whitespace altogether. In my experience, though, the most common indentation (tab) lengths are 2 spaces and 4. My personal preference is 4, but plenty of other people will say 2.
I will say, though, that if you're using more than 4, you're either going to need to break your more nested logic up into multiple lines, or you're going to end up with a lot of overruns -- even with only 4 spaces, I often find myself running over 80 characters.
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 ...)