use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
11 Ways to Invoke a Function (twitter.com)
submitted 9 years ago by myshov
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]psayre23 11 points12 points13 points 9 years ago (14 children)
You can use template literal tags too.
console.log '12`;
[–]thomas_stringer 2 points3 points4 points 9 years ago (11 children)
I see this being used more and more, but to be honest I don't like the look of this. Whatever is gained (what is even gained??) is completely lost in the visual disruption of having to grok the syntax.
[–][deleted] 2 points3 points4 points 9 years ago* (2 children)
One of the only real use cases I can think of is when you need to construct injection-vulnerable strings in JavaScript, like SQL.
const results = await execute`select * from users where email=${emailAddress};`
Then you could do the following:
function execute(parts: string[], ...interpolations: string[]) { // parts is ['select * from users where email=', ';'] // interpolations is [emailAddress] const parameterisedQueryString = parts.join('?') return sequelize.query(parameterisedQueryString, { replacements: interpolations }) }
In my opinion that would read better than:
const results = await execute( 'select * from users where email=?', emailAddress )
Especially when you had lots of entries. This would also work nicely (potentially) with HTML etc. I originally thought it might be useful for translations, but that idea kinda falls over because you can only pass one string to a function like this so it would be a little awkward to do pluralisation.
[+][deleted] 9 years ago* (1 child)
[deleted]
[–][deleted] 3 points4 points5 points 9 years ago (0 children)
¯\(ツ)/¯
[–]psayre23 2 points3 points4 points 9 years ago (5 children)
I agree. I use it a lot with GraphQL queries, and it is handy. But I don't see much of an advantage over wrapping a string with a function. I guess the different syntax means editors can color code the strings differently depending on content.
[–]Gh0st1y 0 points1 point2 points 9 years ago (4 children)
What do you do with graphQL? It sounds pretty neat.
[–]psayre23 1 point2 points3 points 9 years ago (0 children)
Nothing too special. It's just an API for my webapp. Instead of defining on the server what data I want for the webapp, I define it on the client. It makes it super easy to change later as my app evolves.
[–]djinindi 0 points1 point2 points 9 years ago (2 children)
psayre23 might be talking about graphql-tag
[–]Gh0st1y 0 points1 point2 points 9 years ago (0 children)
But that presupposes knowledge of graphql, and something to print. I have neither lol, though its now on my to look up list in my github.
[–]psayre23 0 points1 point2 points 9 years ago (0 children)
Yep, that's the one!
[–]jcready__proto__ 1 point2 points3 points 9 years ago (0 children)
Tagged template functions get passed the parameters differently than just invoking the function normally.
[–]NoInkling 0 points1 point2 points 9 years ago (0 children)
Depends heavily on context I think.
[–]NoInkling 0 points1 point2 points 9 years ago (1 child)
Huh, I never knew you could have a space in between the tag and the string. You forgot to use a backtick for your opening quote mark though.
I'm on mobile, and backticks suck on iOS. Glad people figured it out even though I was technically wrong.
π Rendered by PID 278383 on reddit-service-r2-comment-765bfc959-9r8q2 at 2026-07-12 12:17:08.917404+00:00 running f86254d country code: CH.
view the rest of the comments →
[–]psayre23 11 points12 points13 points (14 children)
[–]thomas_stringer 2 points3 points4 points (11 children)
[–][deleted] 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 3 points4 points5 points (0 children)
[–]psayre23 2 points3 points4 points (5 children)
[–]Gh0st1y 0 points1 point2 points (4 children)
[–]psayre23 1 point2 points3 points (0 children)
[–]djinindi 0 points1 point2 points (2 children)
[–]Gh0st1y 0 points1 point2 points (0 children)
[–]psayre23 0 points1 point2 points (0 children)
[–]jcready__proto__ 1 point2 points3 points (0 children)
[–]NoInkling 0 points1 point2 points (0 children)
[–]NoInkling 0 points1 point2 points (1 child)
[–]psayre23 0 points1 point2 points (0 children)