Comparing jq VS js String Interpolation
Pavol Z. Kutaj

Pavol Z. Kutaj @pkutaj

About: A public interface of my current learnings. The focus is on everything from vim, python to cloud. Imperfect. Impersonal. Never too far from my terminal.

Location:
Brno, Czech Republic
Joined:
Jan 26, 2021

Comparing jq VS js String Interpolation

Publish Date: Oct 18 '24
1 0

The aim of this page is to explain string interpolation based on the particular example of using JQ tool and JavaScript.

  • String interpolation allows inserting variables and expressions into strings.
  • JQ tool uses \(.variable) for string interpolation.
  • JavaScript uses ${variable} for string interpolation.
  • Example of JQ tool:
echo '{ "id": 12345, "subject": "Subject line here" }' | jq -r '"\(.id) \(.subject)"'
  • In JQ tool, variables are enclosed in parentheses and prefixed with a backslash.
  • Example of JavaScript:
const id = 12345;
const subject = "Subject line here";
const result = `${id} ${subject}`;
console.log(result); // Output: 12345 Subject line here
  • In JavaScript, template literals are enclosed in backticks.
  • Variables are embedded using `${}`.
  • Template literals allow embedding expressions and multiline strings.
  • String interpolation is useful for generating dynamic strings.

LINKS

Comments 0 total

    Add comment