javascriptstringvariablesvariable-assignmentassignment-operator

dollar sign $ as an assignment operator for a value of string in vs code ( js ) does not work or highlighted


function sayHello (userName)  {
    console.log ('Hello ${userName}') ;
}

sayHello ('Mena') ;

function sayHello (userName)  {
    console.log ('Hello ${userName}') ;
}

sayHello ('mena') ;

// i expected to show say ( Hello Mena ) in the console //


Solution

  • You need to use backticks(`) instead of (').

    Example:

    function sayHello (userName) {
        console.log (`Hello ${userName}`);
    }