Home >Web Front-end >JS Tutorial >Why Does Using Backticks with `console.log` Produce a `[\'1\', raw: Array[1]]` Output in Google Chrome?
JS Mystery: Backticks (…) Invoking Functions
In Google Chrome, upon executing console.log1, an output similar to console.log1["1", raw: Array[1]]` is produced, sparking questions about the enigmatic behavior of backticks in calling functions and the nature of the "raw" array.
To unravel this mystery, we delve into the world of ES-6 Tagged Templates. These functions accept parsed values of template strings and separate values, enabling custom post-processing. In the case of console.log1, the tagging function is passed the value "1", which is then appended as ["1", raw: Array[1]]` and subsequently printed.
Behind the scenes, Babel transpiles the ES-6 code to a form accepted by browsers before passing the tagged value to console.log. This process involves the transpilation of:
_taggedTemplateLiteralLoose( ["1"], ["1"] );
The result of this transpilation is then passed to console.log, which outputs the array, explaining the presence of both "1" and raw: Array[1].
The above is the detailed content of Why Does Using Backticks with `console.log` Produce a `[\'1\', raw: Array[1]]` Output in Google Chrome?. For more information, please follow other related articles on the PHP Chinese website!