Backticks instead of quotes

Has anyone else noticed that, at least in the beginning JS courses you are forced to use quotes rather than backticks? Just an observation and I understand that they would have to update the backend for all the code that is acceptable to allow the answer in quotes and backticks. I like backticks.

Hmm, I did not notice that, but sure enough. I prefer to use backticks too since there is not need to escape single or double quotes. The current JS course has quiet a few problems that could be solved in it currently.

From what I understand their is a lot of work scheduled to be done involving it at some point in the future.

Possibly because quotes denote a string, whereas backticks denote a template literal. They’re not quite the same thing, and if I remember correctly the course introduces strings much earlier than it does interpolation… which might explain it. :slight_smile:

Template literal or not, backticks are still valid quotation marks through the whole of JS, though some use cases might surface that won’t permit them (not sure of any, just now). We can even use them in the expression template, itself with no effect on the outer quotes of the string.

2 Likes

Consider,

console.log(
 `${n}
  ${n.toString(10).split(``).map(
    x => isAlpha(x) ?
      x === x.toLowerCase() ?
        x.toUpperCase() :
        x.toLowerCase() :
    x).join(``)
  }`
)

That’s from a post earlier today. isAlpha() is a helper function that can be found in that post. I tweaked it to see if split and join would take the quotes, and they do.

Heck, let’s go all out…

const isAlpha = x => `Z` >= x && x >= `A` || `z` >= x && x >= `a`

const toggleCase = u => `  ${u}
  ${u.toString().split(``).map(
    x => isAlpha(x) ?
      x === x.toLowerCase() ?
        x.toUpperCase() :
        x.toLowerCase() :
    x).join(``)
  }`
n = `AbCd4EfGh5IjKlM6nOpQrS7tUv8WxYz`
console.log(toggleCase(n))
n = 123456789
console.log(toggleCase(n))
n = x => x
console.log(toggleCase(n))
n = [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(toggleCase(n))
n = [
  `A`,`b`,`C`,`d`,`E`,`f`,`G`,`h`,`I`,`j`,`K`,`l`,`M`,
  `n`,`O`,`p`,`Q`,`r`,`S`,`t`,`U`,`v`,`W`,`x`,`Y`,`z`
]
console.log(toggleCase(n))
  AbCd4EfGh5IjKlM6nOpQrS7tUv8WxYz
  aBcD4eFgH5iJkLm6NoPqRs7TuV8wXyZ
  123456789
  123456789
  x => x
  X => X
  1,2,3,4,5,6,7,8,9
  1,2,3,4,5,6,7,8,9
  A,b,C,d,E,f,G,h,I,j,K,l,M,n,O,p,Q,r,S,t,U,v,W,x,Y,z
  a,B,c,D,e,F,g,H,i,J,k,L,m,N,o,P,q,R,s,T,u,V,w,X,y,Z

All with a single expression.

1 Like

LOL that was great @mtf

I am redoing the Javascript portion of Codecademy and backticks seem to work in the Function’s lessons. I changed

function sayThanks(name) {
  console.log('Thank you for your purchase '+ name + '! We appreciate your business.');
}

function sayThanks(name) {
  console.log(`Thank you for your purchase ${name}! We appreciate your business.`);
}

Introduction and Conditionals lessons would not let me. I could be wrong though.

1 Like

The lessons may not be able to match these newer string patterns. It won’t mean the string is invalid, only that the SCT is expecting ES5 strings. Sometimes the SCT is so strict we have to use one or the other quote, without even a choice there. Again, it is the lesson checker, not the syntax.

2 Likes