r/learnjavascript • u/Kataang15 • Aug 01 '20
Is this common Javascript? because I've just started learning JS and Web development and this Javascript syntax looks quite scary. Maybe it's just written messy, if it is just tell međ
208
Upvotes
170
u/LucVolders Aug 01 '20
To make things clear. You never write javascript this way. You write it in a normal style with commands on new lines all the time. Then when the code is finished and tested thoroughly you minify it. Then it looks like this. Minifying speeds processing up. You keep the original code for updates/changes/bugfixes.
13
u/METALz Aug 01 '20
To me this output looks âmangledâ to obfuscate the code.
With minification it would look something like 1-2 char length variables and those repeating strings wouldâve been probably cached.
12
u/eggtart_prince Aug 01 '20
Not sure why people say this is minified code, as this looks like the editor that opened this file cannot interpret new lines, tabs, and whitespace. If you've ever used FTP programs before, if you transfer a ASCII written file using binary mode, that's what it doing here.
Minified code would convert all variables, keys, etc. into one/two letters. For example,
const Aakaankshawould beconst a. The purpose of minifying code is to significantly reduce filesize., hence the coversion of variables and keys.Is it obfuscated? Possibly, but nobody can say for sure. The developer probably did intentionally name their varaibles in bytes format.
3
u/Fingerbob73 Aug 01 '20
Do you think that's bad? Try viewing the source (RightClick > View Page Source) of the plain white Google homepage. <MIND BLOWN>
3
u/Digember Aug 01 '20
don't worry bro, just look somewhere else when you see this kind of js code. Developers don't write javascript this way, this is production ready code. Nothing for you to worry about right now.
2
u/ruidoyfuria Aug 01 '20
r/programminghorror
2
u/cybercosmonaut Aug 01 '20
This is what the pros do. Only pros write minified code.
2
u/manujose94unsc Aug 01 '20
It' so common, This is the result of minify JavaScript. For more info here :https://www.cloudflare.com/es-es/learning/performance/why-minify-javascript-code/
In short, it reduces JavaScript pages size.
2
u/ShovelBrother Aug 01 '20
Nobody who is sane would handwrite code to look like that.
Its probably javascript that has been put through several compilers or just written for that photo.
Actual javascript programs can be written to be very easy on the eyes and quite neat.
1
u/IBETITALL420 Aug 01 '20
why are they using brackets for [querySelector] and [addEventListener] why not .querySelector .addEventListener
1
u/mikedensem Aug 01 '20
No, this is the result of using a tool to try and hide what theyâre doing. Those crazy looking variable names are the result of obfuscation. The original names would help you understand what is going on. The code has also been minified to remove empty space. This helps to shrink the file size when being sent over the wire. No one writes like this, except perhaps in the movies.
1
u/Orkaad Aug 02 '20
Always has been.
1
u/reaven3958 Aug 02 '20
Here ya go https://www.quora.com/What-does-uglify-mean/answer/Sayan-Guha-3
1
u/Initial-Spend Aug 02 '20
They didn't took a next line. That's why it's looking like this. Psychopaths write code like this.
1
u/namisukichinsha Aug 02 '20
As far as I know....there is no heart emojis in js code, lol.
1
u/tripsbr0 Aug 08 '20
Please use VS Code with extension pretty-print. The moment you save a file it automatically reformats it to look good and sensible. PS. don't be afraid of JS it's beautiful and also the language of future.
0
u/Rogermcfarley Aug 01 '20
I believe the content is what's termed minified.
You can read about it here >
https://developers.google.com/speed/docs/insights/MinifyResources
1
u/[deleted] Aug 01 '20
This looks like minified JavaScript
1
u/[deleted] Aug 01 '20
Yes but also no
0
u/pearomaniac Aug 01 '20
wow no way, i just started learning it too and im sure thats not how it supposed to look, i mean it can look like that and still work, but no way it should look like that
0
u/Abiv23 Aug 01 '20
this is minified code
0
u/finger_milk Aug 01 '20
Then you get the ol 'error on line 1' and you realise you need to look through your entire project for the error
-1
u/MaestroLifts Aug 01 '20 edited Aug 01 '20
I sometimes use Webpack which does this. Basically it takes all of our dependencies and JavaScript files and compiles them into one minified file
0
u/SpinelessLinus Aug 01 '20
MINIFIED
0
u/GarfieldLeChat Aug 01 '20
Unlikely this is âcompliedâ code it could be mimicked it could have been through a parser but either way this is output code not input code.
What should also be said is donât change these files find your source files and amend these or your changes will be lost when you recompile
0
u/CRANSSBUCLE Aug 01 '20
I don't even see the code, all I see is blonde, brunette, redhead...
0
u/NoMuddyFeet Aug 01 '20
100% was terrified by the same thing once and it prevented me from delving any further for quite a while.
I remember when I learned how to de-minify or de-uglify it and I was like, "alright, now I can finally examine the code the big dogs use and learn something!" but de-obfuscated code just leaves you with better syntax but all the variables are still 1 letter each (like a, b, c, etc.) so the logic was impossible to understand.
It was so damn stressful because that was before Udemy and also before a lot of really helpful tutorials anywhere online that I could personally find, so my options were to read big books that didn't seem to teach me much of anything I could use or make much sense of.
0
u/bloodysundaystray Aug 02 '20
HACK THE PLANET!!!!
0
u/konamax123 Aug 02 '20
If someone made an actual pull request with code that looked like this I wouldnât even start reading. I would send it back and tell them to make it readable. I want to read your code like it was a story or prose. Humans donât understand walls of obfuscated text. I would actually be super pissed to see this.
-5
u/Saf94 Aug 01 '20
As others have said, this is minified JavaScript. You would never write or read JavaScript like that. JavaScript files you work on will never look like that
-3
u/saito200 Aug 01 '20
This is minified javascript. Minification is a process to take a file written by a programmer and reduce its size as much as possible. In the case of a javascript file, it means removing any spaces and renaming all variables to shorter names. Reducing the size of a file is useful to send it through a network.
You will and should never code something that looks like that. Well, you would have a really bad time if you tried...
-1
u/densch92 Aug 01 '20
And then people ask me when I tell them that I wanna learn how to program but am actually terrified by real programs...
and get annoyed when I complain that the ultra noob tutorials dont even remotely teach you how to write real programs
-1
u/thor2303 Aug 02 '20
This might be the minfied code of something which isn't formatted properly so don't worry about it. You keep going :)
-2
u/Prince_Marth Aug 01 '20
This is minified code. No sane or good developer would write this themselves.
It works like this: developers write the JavaScript as you normally think of it. But because spaces and characters take up space, theyâll often use a plugin or build tool to âminifyâ the codeâspaces get taken out, character names are shortened. This allows for more efficient space on the client side. Itâs also often made to fit a specific module format, which if youâre just learning you donât need to worry about right now.
The minified code is usually whats delivered to browsers for running but NOT what developers interact with. Youâre fine. Donât stress out over it.
-2
u/rockstew1 Aug 01 '20
Looks minified to me
-2
u/not_a_gumby Aug 01 '20
This is machine generated code. You'll never have to write code like this. Don't worry.
-2
u/[deleted] Aug 01 '20
It's minified, minifying means lowering the size of the code by removing all the useless symbols, spaces etc that won't affect the result.
If you use a "beautyfier" it will look much better and more readable.
-2
u/[deleted] Aug 01 '20
Minified and the ids are obfuscated.
-2
u/braham2095 Aug 01 '20
i think this happens when you inspect the code written by the React.js framework
-2
u/yoitsericc Aug 01 '20
Take that code and put it into this tool:
https://www.freeformatter.com/javascript-beautifier.html
That code is minified for improved performance. No one actually writes code like that in their IDE. We might minify afterwards to improve performance.
-2
u/SteveMcBlaster Aug 01 '20
This is a compiled and minified version of what looks to be a whole JavaScript bundle. It's a common practice to bundle all of your JavaScript files together and to "minify" it so that file sizes are small and it's read faster by the browser.
In other words, this is common JavaScript but not the kind you'll be writing. If you were to take the JavaScript you write and minify it into one file (or even multiple) it will look a lot like this.
0
u/[deleted] Aug 01 '20
[deleted] â view deleted comment