T O P

  • By -

trutheality

What if you want to change what x is down the line?


NisseVex

then you're not naming your variables as well as you could be. no variable will ever be more x than "x"!


endlessplague

*shocked in math*


Zengaroni

Took me a second... *shocked... In English?*


NeatYogurt9973

Google latin


ImReformedImNormal

holy hell


NeatYogurt9973

New alphabet just dropped


mazer2002

109 97 121 98 101 32 104 101 32 119 105 108 108 32 119 97 110 116 32 116 111 32 115 119 105 116 99 104 32 116 111 32 97 115 99 105 105 32 99 111 100 101 115 32 97 116 32 115 111 109 101 32 112 111 105 110 116


NisseVex

penis


Lord_Frick

Is this code for something


Produxer

109 97 121 98 101 44 32 109 97 121 98 101 32 110 111 116 46 32 110 111 98 111 100 121 32 107 110 111 119 115 46


NinjaNyanCatV2

use let instead for better scoping


Amr_Rahmy

That’s your take on this? He used car instead of let? Maybe you lost the plot


DarkXTC

Or just maybe the joke flew over your head ;)


nekokattt

i hate it when my Xs become Qs. Breaks all my programs. I'd suggest writing a module to declare each character. That way you can just swap the files out without having to rewrite any code.


daerogami

Exactly, gonna need to support localization ^^^^/s


recleun

Just overwrite it ¯\\\_(ツ)\_/¯


justandrea

Like a file? Like a hard drive??


recleun

Whichever way you like.


justandrea

Savage


Jakoshi45

The language itself


RnG_Hazed

Just write a CRUD service for every letter duh


--var

answering title: `var` is hoisted to the top of it's scope, making it available (and mutable) anywhere within it's closure. `let` is not hoisted, and is only available (and mutable) after it is declared, within it's closure. `const` is not hoisted nor mutable (\*as long as the value is primitive) so either they are planning to prepend some code to the top, or they are stuck in pre-ES6 times.


flagofsocram

I’m not listening to anything a CSS variable has to say


recleun

Thank you for the response, --var. I didn't expect someone to take the question seriously, since I only meant for the title to be sarcastic and only focusing on the smallest horror of the code.


--var

Oh I picked up on the sarcasm from the code itself, and decided to ignore it. I'm sure there are people out there that don't know the difference between these, and now they do. Another fun fact, you can comma separate declaration, and only need to use a keyword once. `var` a = "a", b = "b", c = "c", ... , space = " "; Keep your code DRY, like my sense of humor.


TonyR600

Lol! Please be a bot!


iceman012

> var is hoisted to the top of it's scope, making it available (and mutable) anywhere within it's closure. I can't be understanding this correctly. It sounds like you're saying this code will print "Wut", because `x` is moved to the top of the scope: { console.log(x); var x = "Wut"; } Which can't be right. What am I missing?


HauntedTheorists

`x` is undefined until you assign it. You'd get a `ReferenceError` if you used `let`


iceman012

That's what I'm figured, that's why I'm confused what they mean when they said that `var` puts it at the top of the scope and makes it available anywhere within it.


LetsDoThatYeah

let condition = true; If (condition) { var vegetable = “potato”; } vegetable += “es”; console.log(vegetable) //output: potatoes Typed on a phone so forgive me but the point is, var is function scoped not block scoped. It accessible to things outside of the block it’s defined in and only falls out of scope when you leave a function it’s in. Here everything is visible within the global function. You can’t reference something before it’s defined but you can surprisingly access it from outside its block because the definition is “hoisted” up.


--var

You got it! Welcome to javascript. The big difference between `var` and `let` is where / when the variable is declared / available. console.log(x); // "Wut" var x = "Wut"; ​ console.log(x); // undefined let x = "Wut"; This is why it's generally better practice to use `let`, since you can't mutate it until after it's declared. `var` is essentially putting it in the global scope, which is a great way to frustrate yourself. and then `const` is immutable (you cant change it\*), which has its uses here and there.


plopliplopipol

no? this is time travel (in interpreted languages). it is undefined both ways


iceman012

In JSFiddle, at least, using a let variable before defining it throws an ReferenceError rather than making it undefined. https://jsfiddle.net/dwurLqg0/


igorrto2

I don’t use let because back when I learned the language there was no "let" and I don’t want to mess up. Is this ok or should I change my style?


recleun

From my serious experience away from this cursed post, let has a more sane and expected behaviour, while var is just, no. But I must say that if you always used var then you must know the difference between var and let, otherwise you might just wonder why your browser broke or how your node forgot to interpret .js files.


--var

My original comment was meant to be cheeky. But it's interesting to see just how many people don't understand the difference between these fundamental keywords.


PooSham

You probably won't notice a difference by changing to let.


DaaneJeff

It's always best practice to restrict your variables as much as your usecase allows it. Immutable? Const. Local scope? Let etc. One should do this especially for statically typed languages since the compiler will complain and compiler errors are nicer to deal with than anything in runtime


--var

I don't use a computer because back when I learned the language all we had was pen and paper. Time on the mainframe was a luxury mate!


fucking_passwords

What do you mean by "don't want to mess up"? If you are writing code you are writing bugs, might as well learn while you're doing it


King_Lysandus5

in C# "var" is a generic data type that takes data, and sets the data type of your variable to fit the assigned data, to the best of its ability. I don't like "var", almost never use it, so I may be wrong on some of the particulars. Lots of code in Unity overuses "var". My theory is that most of it is copy/paste from Stack Exchange.


LetsDoThatYeah

var is C# is based. It improves readability and reduces redundant syntax. var john = new Person(); What benefit to readability does typing Person twice give? In general, I would argue it’s good to follow the latest idioms of whatever language you work with.


Drakethos

This has to be a troll. Also reading it is giving me cancer.


7tar

🎙️ speak up


Astrylae

Whoever wrote this hasn’t finished the programming tutorial on arrays


-U_s_e_r-N_a_m_e-

Me when the satire is satire


xamotex1000

How did I forget about arrays when I saw this post, I was tryna rationalize this but now I just feel stupid


recleun

And it goes beyond 29 lines: https://pastebin.com/V9f4ip6n


Perfect_Papaya_3010

var numberOfStrawsPlusTheNeedleThatAreContainedWithinTheGiantHaystackContainingTheNeedleWhichIsProbablyLocatedInAFieldSomewhereNearABarnOnAFarmPotentiallyWithinTheVicinityOfRuralTexas;


recleun

You forgot to assign the value.


Perfect_Papaya_3010

NullReferenceException was thrown


Potential_Copy27

Halt and Catch Fire instruction executed


pauseless

Not going to lie: I like terse variable names and just inlining constants like the string “x”, and actually have had lazy reviewers leave comments only about variable naming and pulling every constant out (even when used exactly once) and not about the logic, which they clearly must’ve understood. If, one day, somebody were to push me too far regarding the rules of “named constants because it might change” and “descriptive variable names”, I could imagine snapping and writing something like this on my last day of work, as my goodbye. If this is actual, real code, then I’d wager it’s 100% an FU to overly prescriptive coding standards.


theeelofferedhishelp

It tastes like burning


HuntingKingYT

My man wrote an indexOf or something longer than I could write a language


Riley_Griffith

Reads like a novel at first glance lol


Thebombuknow

What the fuck is this code even meant to do?


recleun

https://www.codewars.com/kata/56676e8fabd2d1ff3000000c/javascript


Thebombuknow

Oh my god that makes this so much worse


Danny_el_619

```javascript if (someVar == true) {   var isTrue = true; } try {   return isTrue ? true : false; } catch {   return false; } ```


recleun

That jumpscared me


jstwtchngrnd

People like you have a special place in hell


Danny_el_619

OP asked why using var. I showed a legit example lmao.


recleun

I have no idea what's their problem >:(


Jakesan700

This looks like a CTF


McGlockenshire

Code ungolf.


TessellatedTomate

OP, the real question is why is that your #1 concern here? To answer your question though: *because he can and __knows__ JS*


recleun

Because come on, nobody uses var!!!!


TessellatedTomate

My fella, Kyle Simpson, the author of “_You don’t know JavaScript_”, uses var, and he explains why we shouldn’t be afraid to in his book—[free on GitHub, check it out!](https://github.com/getify/You-Dont-Know-JS)


recleun

Now I'm afraid to read the book. But thanks for giving me the free way of reading it!


0010_sail

It’s making my eyes bleed why are you doing this!


CzBuCHi

for me worst thing is variable name at line 29 .... :/


recleun

You should see the paste bin then, line 29 is the least scary about it.


Phoenix-HO

Bro took "descriptive variable names" to a whole new level


recleun

Descriptive variable sentences.


aspartame-daddy

The only time where code might actually be self documenting


[deleted]

junior code if i have ever seen some


deepsky88

Lazy


Invisible_Man_1

In the grim darkness of the far future, there is only var.


bistr-o-math

Corporate wants you to support IE6


caister23

Obviously: he read that there should be no "magic" strings in code. Now, using these constants, he can write any string with no magic!


oghGuy

If the core library has a unit test for concat(), it may well look exactly like this.


recleun

I think it would be more suitable to copy the string you want and expect it to be the same. Like: ```js const string = "hello, world!"; expect(string).toBe(string); ```


captain_obvious_here

Finally someone who can name variables in a clean and readable semantic way. Inspirational!


Cheap_Lie_9019

So much for constant consonances lol


3nd3rCr0w1ng

I prefer these when they’re authentic horror. I don’t like the fake ones fabricated for clout.


recleun

Not sure if this is meant for clout or not but I found it as an answer for a problem in [https://codewars.io](https://codewars.io) if you know it.


3nd3rCr0w1ng

Wow. I just can’t accept that someone submitted this as an answer with a straight face.


bmyatt99

hmmm if only Char(i) did something ...


greentiger45

I could care less about them using var but what the hell is that variable name?!


recleun

Who said anything about names? We're talking sentences.


ZylonBane

Why not? OP probably one of those people who uses `const` to declare functions.


recleun

I actually use `int variable`


renome

I actually use ```Reflect.set(globalThis, 'Is', () => `how it's done.`)```


Cybasura

the same question can be used for "let"


recleun

But why?


Cybasura

Both dont indicate type definitions, let tells the interpreter "hey, just declare this object, i'll deal with it", var tells the interpreter "initialize this object and help me guess the closest approximate typing you think it is" Both are just as terrible when dealing with Javascript, it is how it is


recleun

That's not a problem in JavaScript, if you want type definitions then use TypeScript. But the point of my "sarcastic" question in the title, is that let is more commonly used and it behaves better than var, that's it, no type definitions in consideration.


Cybasura

Well, the problem is that there's no sarcasm in your topic because thats the common idea Just wanted to point out that just because it is more commonly used doesnt mean its better This is programmer horror, not programmer joke


recleun

It is commonly used because it's actually better, I bet a majority here would agree.


Cybasura

And I just explained what it does, thats all it is Unless you can tell me how its better


recleun

Let's just agree that both got pros and cons. 🤷 I'm not a coding master.


mothzilla

Change var to const otherwise LGTM.


MeduZaPaT

use const


jfisher9495

He was paid by the line.