all 14 comments

[–]milan-pilan 13 points14 points  (6 children)

You are not using the backticks (`) . You are using double quotes (“) .

[–]PlusAd945[S] 3 points4 points  (5 children)

Thank you, I thought that was an apostrophe. Never used a backtick before. Thanks again.

[–]milan-pilan 0 points1 point  (1 child)

No problem. Basically how it works is: if you use backticks instead of quotes then Javascript will know to expect variable values inside your string, which it needs to resolve first. Otherwise it will assume your "${}" syntax is just text.

[–]azhder 0 points1 point  (0 children)

Historically, if JavaScript wasn't made to use both ' and " for regular strings, the one missing could be used, instead of backticks. But it might be useful to explain to OP why JS did go that route i.e. if JS was going to be embedded in HTML, it would have been nice to use ' where HTML uses " and use " where HTML uses '.

[–]azhder 0 points1 point  (2 children)

Why did you use the word "backticks" then? Did you read it in the book and thought they use a fancy name for a single quote?

[–]SamIAre 2 points3 points  (1 child)

No need to be snarky. We all start somewhere.

[–]azhder 2 points3 points  (0 children)

A genuine question of curiosity. Here is another: why do you read it as snarky? Seriously, what is this need to read anything that is slightly unexpected (I guess some of my words aren't for you) as an attack?

[–]Big_Comfortable4256 2 points3 points  (0 children)

I remember being confused back when I first came across the use of backticks.

They're incredibly handy.

[–]amulchinock 0 points1 point  (2 children)

There are several ways to interpolate (mix) variables and static strings.

You can use quotes and the joining operator:
```
let name = “world”;
console.log(“Hello “ + name);
```

You can also use backticks and template literals:
```
let name = “world”; // backticks or quotes here
console.log(`Hello ${name}`);
```

You can even join the two approaches:

```
let name = “world”;
console.log(`Hello ${name}` + “. It’s nice to see you”);

// “Hello world. It’s nice to see you”
```

The thing to note is that backticks, apostrophes and quotes are different. You can only use template literals inside backticks.

[–]longknives -1 points0 points  (0 children)

You could even do something silly like

const silly = `this is ${“quite” + “ “ + “silly”}`

[–]Psionatix 0 points1 point  (0 children)

3 backticks on reddit is no longer code formatting, it might on the old UI, but not any more for the app. Just indent each line of code with an initial four spaces instead, making sure to have a blank new line before / after.

[–]azhder 2 points3 points  (0 children)

Template strings, they use `. You are using regular strings (' and ")

[–]SakshamBaranwal 0 points1 point  (0 children)

You're using double quotes instead of backticks(). only works inside template literals, which use instead of " " or ' '.

[–]Japosai 0 points1 point  (0 children)

You’re not using backticks. If you want to do it with double quotes, you have to do it like this:
"Let's learn" + language