Home > front end >  Arrow function not reading
Arrow function not reading

Time:02-12

I'm using VSCode & I'm trying to use an arrow function & something strange happened.

Input:

const name = 'Daniel';

const printName = (name) => 'Hi, my name is ${name}';

console.log(printName(name));

Expected Output:

Hi, my name is Daniel

Actual Output:

Hi, my name is ${name}

I don't know how to fix this, help...

Btw, I'm a beginner to VSCode.

CodePudding user response:

Replace single quotes ' with backtick `

const printName = (name) => `Hi, my name is ${name}`;

CodePudding user response:

When using a string template the quots should be of this type: ` (backticks). meaning it should be like so:

const printName = (name) => `Hi, my name is ${name}`;

CodePudding user response:

Do this,

const name = 'Daniel';

const printName = (name) => "Hi, my name is "   name

console.log(printName(name));
  • Related