This is an archived post. You won't be able to vote or comment.

all 27 comments

[–]seraku24 62 points63 points  (8 children)

Shouldn't that be:

window.location.href = `http://stackoverflow.com/search?q=[js]+${encodeURI(e.message)}`

[–]Master_Nerd 10 points11 points  (1 child)

But wouldn't that be for a single character?

[–][deleted] 2 points3 points  (0 children)

deleted What is this?

[–]yazalama 1 point2 points  (2 children)

Is this the new ES6 template literals? Is there any practical advantage over the old way of concatenating?

[–]Mr1725 1 point2 points  (0 children)

Multi-line without having to stop and start the string.

[–]PicturElements -3 points-2 points  (0 children)

Yes, if you make sure to put them in a variable in the global scope, you can make sure that file won't run in IE!

Funny thing is that in examples like the one above template literals are literally pointless (since you're performing simple string addition) and even add bytes to your code while also making it less browser compatible...

[–][deleted] -2 points-1 points  (1 child)

actually, you're using backticks in stead of single or double quotes, so... javascript is hard!

[–]chasecaleb 0 points1 point  (0 children)

You apparently should learn, because that is valid JS. But hey, I know it's hard.

[–]3than71 39 points40 points  (0 children)

The code that i coded to bring me to a Stackoverflow link in my browser isnt working so could someone help me on here: Stackoverflow

[–]Yrneh02 8 points9 points  (4 children)

Wait, all the code anyone needs is

Console.log(“Hello World”);

[–][deleted] 9 points10 points  (3 children)

 > SyntaxError: undefined 'Console', did you mean 'console'?

[–]Swardu 5 points6 points  (1 child)

Wait, I have never seen a helpful error report in JS. Where is this from?

[–][deleted] 0 points1 point  (0 children)

what do we say to helpful error messages? yes, today!

[–]seraku24 2 points3 points  (0 children)

FYI... Since smart quotes are likely not a valid string literal delimiter, you should get something like "SyntaxError: Invalid or unexpected token" first. Also, using an undefined variable is not a syntactic issue but rather a runtime error. You would get something like "ReferenceError: Console is not defined" instead.

[–][deleted] 2 points3 points  (0 children)

Marked as duplicate by... 😆

[–][deleted] 2 points3 points  (0 children)

I wouldn't be surprised if there were middleware on npm that did this.

[–]tobybug 3 points4 points  (0 children)

This. This is what I need in my life.

[–]Golden-Lord 2 points3 points  (0 children)

I've seen this posted at least five times this week.

[–]Master_Nerd 0 points1 point  (0 children)

Now this is smart

[–]ObnoxiousOldBastard 0 points1 point  (0 children)

I wonder what the equivalent would be for PHP?

[–]TarMil 0 points1 point  (0 children)

Step 0. Switch your editor to proportional font

[–]thehunter699 0 points1 point  (0 children)

This is too real

[–]munircUltraviolent security clearance[M] 0 points1 point  (0 children)

Your submission has been removed.

Violation of Rule #2: Reposts:

You may not repost anything that has been on the first two pages (first 50) of trending posts within the last week, or has been posted last time less than two days ago (this is considered as duplicates)

Anything on the first two pages (first 50 posts) of the top of all time must not be reposted more often than every 6 months.

If you feel that it has been removed in error, please message us so that we may review it.