Usage of the backtick character (`) in JavaScript

后端 未结 9 2141
囚心锁ツ
囚心锁ツ 2020-11-22 00:51

In JavaScript, a backtick seems to work the same as a single quote. For instance, I can use a backtick to define a string like this:

var s         


        
9条回答
  •  被撕碎了的回忆
    2020-11-22 01:23

    Apart from string interpolation, you can also call a function using back-tick.

    
    var sayHello = function () {
        console.log('Hello', arguments);
    }
    
    // To call this function using ``
    
    sayHello`some args`; // Check console for the output
    
    // Or
    sayHello`
        some args
    `;
    
    

    Check styled component. They use it heavily.

提交回复
热议问题