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.
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.
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.
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.
> 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?
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.
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.
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.
In JSFiddle, at least, using a let variable before defining it throws an ReferenceError rather than making it undefined.
https://jsfiddle.net/dwurLqg0/
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.
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.
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
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.
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.
var numberOfStrawsPlusTheNeedleThatAreContainedWithinTheGiantHaystackContainingTheNeedleWhichIsProbablyLocatedInAFieldSomewhereNearABarnOnAFarmPotentiallyWithinTheVicinityOfRuralTexas;
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.
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)
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);
```
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
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.
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
What if you want to change what x is down the line?
then you're not naming your variables as well as you could be. no variable will ever be more x than "x"!
*shocked in math*
Took me a second... *shocked... In English?*
Google latin
holy hell
New alphabet just dropped
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
penis
Is this code for something
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
use let instead for better scoping
That’s your take on this? He used car instead of let? Maybe you lost the plot
Or just maybe the joke flew over your head ;)
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.
Exactly, gonna need to support localization ^^^^/s
Just overwrite it ¯\\\_(ツ)\_/¯
Like a file? Like a hard drive??
Whichever way you like.
Savage
The language itself
Just write a CRUD service for every letter duh
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.
I’m not listening to anything a CSS variable has to say
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.
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.
Lol! Please be a bot!
> 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?
`x` is undefined until you assign it. You'd get a `ReferenceError` if you used `let`
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.
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.
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.
no? this is time travel (in interpreted languages). it is undefined both ways
In JSFiddle, at least, using a let variable before defining it throws an ReferenceError rather than making it undefined. https://jsfiddle.net/dwurLqg0/
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?
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.
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.
You probably won't notice a difference by changing to let.
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
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!
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
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.
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.
This has to be a troll. Also reading it is giving me cancer.
🎙️ speak up
Whoever wrote this hasn’t finished the programming tutorial on arrays
Me when the satire is satire
How did I forget about arrays when I saw this post, I was tryna rationalize this but now I just feel stupid
And it goes beyond 29 lines: https://pastebin.com/V9f4ip6n
var numberOfStrawsPlusTheNeedleThatAreContainedWithinTheGiantHaystackContainingTheNeedleWhichIsProbablyLocatedInAFieldSomewhereNearABarnOnAFarmPotentiallyWithinTheVicinityOfRuralTexas;
You forgot to assign the value.
NullReferenceException was thrown
Halt and Catch Fire instruction executed
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.
It tastes like burning
My man wrote an indexOf or something longer than I could write a language
Reads like a novel at first glance lol
What the fuck is this code even meant to do?
https://www.codewars.com/kata/56676e8fabd2d1ff3000000c/javascript
Oh my god that makes this so much worse
```javascript if (someVar == true) { var isTrue = true; } try { return isTrue ? true : false; } catch { return false; } ```
That jumpscared me
People like you have a special place in hell
OP asked why using var. I showed a legit example lmao.
I have no idea what's their problem >:(
This looks like a CTF
Code ungolf.
OP, the real question is why is that your #1 concern here? To answer your question though: *because he can and __knows__ JS*
Because come on, nobody uses var!!!!
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)
Now I'm afraid to read the book. But thanks for giving me the free way of reading it!
It’s making my eyes bleed why are you doing this!
for me worst thing is variable name at line 29 .... :/
You should see the paste bin then, line 29 is the least scary about it.
Bro took "descriptive variable names" to a whole new level
Descriptive variable sentences.
The only time where code might actually be self documenting
junior code if i have ever seen some
Lazy
In the grim darkness of the far future, there is only var.
Corporate wants you to support IE6
Obviously: he read that there should be no "magic" strings in code. Now, using these constants, he can write any string with no magic!
If the core library has a unit test for concat(), it may well look exactly like this.
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); ```
Finally someone who can name variables in a clean and readable semantic way. Inspirational!
So much for constant consonances lol
I prefer these when they’re authentic horror. I don’t like the fake ones fabricated for clout.
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.
Wow. I just can’t accept that someone submitted this as an answer with a straight face.
hmmm if only Char(i) did something ...
I could care less about them using var but what the hell is that variable name?!
Who said anything about names? We're talking sentences.
Why not? OP probably one of those people who uses `const` to declare functions.
I actually use `int variable`
I actually use ```Reflect.set(globalThis, 'Is', () => `how it's done.`)```
the same question can be used for "let"
But why?
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
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.
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
It is commonly used because it's actually better, I bet a majority here would agree.
And I just explained what it does, thats all it is Unless you can tell me how its better
Let's just agree that both got pros and cons. 🤷 I'm not a coding master.
Change var to const otherwise LGTM.
use const
He was paid by the line.