Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS - Avoid backticks usage without interpolation needs #28

Open
JulienWilhelm opened this issue Oct 10, 2023 · 2 comments
Open

JS - Avoid backticks usage without interpolation needs #28

JulienWilhelm opened this issue Oct 10, 2023 · 2 comments
Labels
⁉️ help wanted Extra attention is needed 🗃️ rule Impacts a rule

Comments

@JulienWilhelm
Copy link

Is your feature request related to a problem? Please describe.

In JS, we can write strings inside :

  • Single quotes ;
  • Double quotes ;
  • Backticks.

By using backticks, we can inject variables that will be evaluated on runtime, just like that :

console.log(`this is my ${variable} content.`);

I made a simple jsperf test to evaluate the performance between each approach.

<!-- HTML -->
<p id="my-para"></p>

// JS. Test 1.
document.getElementById('my-para').textContent = 'A few words...';

// JS. Test 2.
document.getElementById('my-para').textContent = "A few words...";

// JS. Test 3.
document.getElementById('my-para').textContent =  `A few words...`;

Here are the results :

  1. Using double quotes is always fastest ;
  2. Using backticks is always slowest.

Describe the solution you'd like

A dedicated rule?
Backticks without interpolation needs should be avoid.

@JulienWilhelm JulienWilhelm added the 🚀 enhancement New feature or request label Oct 10, 2023
@utarwyn utarwyn added the 🗃️ rule Impacts a rule label Oct 19, 2023
@utarwyn
Copy link
Member

utarwyn commented Oct 19, 2023

Hello, thank you for the rule idea!

Unfortunately, when I try to reproduce on jsperf (a very good tool, by the way!), the results are a bit random and the backticks aren't always the slowest.

image

I think it needs a little more work to validate its relevance. Any help is welcome on this topic 👍

@utarwyn utarwyn added ⁉️ help wanted Extra attention is needed and removed 🚀 enhancement New feature or request labels Oct 19, 2023
@JulienWilhelm
Copy link
Author

Hum. I made these tests again today, and I got various results too!
It seems I was wrong (even if it should be logic)!

Do not close the issue so fast; I will try to make some others tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⁉️ help wanted Extra attention is needed 🗃️ rule Impacts a rule
Projects
None yet
Development

No branches or pull requests

2 participants