Home > Web Front-end > JS Tutorial > Why Does Using Backticks with `console.log` Produce a `[\'1\', raw: Array[1]]` Output in Google Chrome?

Why Does Using Backticks with `console.log` Produce a `[\'1\', raw: Array[1]]` Output in Google Chrome?

Mary-Kate Olsen
Release: 2024-11-26 13:36:14
Original
278 people have browsed it

Why Does Using Backticks with `console.log` Produce a `[

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"] );
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template