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đ
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 Aakaanksha would be const 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.
5
u/Cosmologicon Aug 01 '20
There is whitespace where there needs to be, though, after
constandlet. The fact that whitespace is removed only where it's unnecessary suggest it's processed somehow rather than being a transmission error, though you're right that the variable names are weird for minification.
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
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.
9
u/StoneCypher Aug 01 '20
Yeah, this isn't minified. The labels are unchanged and everything has nine character names.
This is obfuscated. They're different.
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
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
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
10
u/StoneCypher Aug 01 '20
Yeah, this isn't minified. The labels are unchanged and everything has nine character names.
This is obfuscated. They're different.
1
1
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
-2
u/RajjSinghh Aug 01 '20
The code has been minified, which removes things like comments or unnecessary formatting in a way that makes the code itself shorter but keeps the same functionality. You would write it in normal style, then pass it through a program to minify it
1
u/pearomaniac Aug 01 '20
ah ok, understood
6
Aug 01 '20
It's actually been obfuscated. Not the same thing.
Apparently everyone in this subreddit thinks they are the same thing.
0
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
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
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
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
7
u/StoneCypher Aug 01 '20
Yeah, this isn't minified. The labels are unchanged and everything has nine character names.
This is obfuscated. They're different.
Don't "as others have said." You aren't adding anything.
-6
u/fisherrr Aug 01 '20
You copypasting same exact reply 10 times isnât adding that much either tbf
6
Aug 01 '20
It is, though, it's correcting misinformation. In case someone doesn't see his reply on the first 30 dummies to say the codes been minified, they might catch his reply in one of the next 30 "this code is minified" responses.
5
-7
u/Saf94 Aug 01 '20
Ok but I was actually trying to add to the answers who when I posted, just said it was minified by answering the actual question and saying theyâll never have to write code like that so not to worry about it.
The OP thought it was messily written code so I was clarifying that it isnât and theyâll never write code like that.
At the time there was only 2 other comments so I was quite literally adding to it by answering the actual question...
3
u/StoneCypher Aug 01 '20
Ok but I was actually trying to add to the answers who when I posted
Except what you did was to repeat what they said, which was wrong
-4
u/Saf94 Aug 01 '20
Lol ops actual question is is this normal JavaScript code not what is this code? He didnât ask what the code is.
At the time of posting I was the only one who actually answered the question. My answer was it wasnât normal code and he didnât need to worry about it.
Yes youâre right itâs not minified as I said but that wasnât the question and what I said was useful because he wanted to know if it was normal code and I said it wasnât.
3
u/StoneCypher Aug 01 '20
As others have said, this is minified JavaScript
I was actually trying to add to the answers who when I posted
At the time of posting I was the only one who actually answered the question
It's weird how as you go, fewer and fewer people were there before you
Anyway, the answer is wrong, no matter how many people you think gave it first
-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...
5
u/StoneCypher Aug 01 '20
Yeah, this isn't minified. The labels are unchanged and everything has nine character names.
This is obfuscated. They're different.
2
u/saito200 Aug 01 '20
obfuscated
Is that a programming thing? I didn't know
5
u/StoneCypher Aug 01 '20
Yeah.
Obfuscation is generally a thing in programming languages that don't compile (scripting languages and exotics,) where a vendor doesn't want a customer to be able to alter or understand the source.
It's particularly common in situations like a PHP app vendor wanting to sell you a blog engine. PHP even sells a tool for this (Zend)
This is not a particularly successful job, here.
Amusingly, in the JS community, we even have tools that will make statistical guesses what the name used to be, with fair accuracy, eg jsnice
-2
u/TijmenTij Aug 01 '20
Its basicly code that does nothing
1
Aug 02 '20
Its code rewritten in a way that intentionally makes it hard to understand what the code is doing to make it harder to reuse in someone else's code base.
-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
0
Aug 02 '20
Ultra-noob tutorials are to teach you concepts, writing "real programs" come with practice and maybe more advanced tuts.
1
u/densch92 Aug 02 '20
and normal tutorials dont seem to be a thing.
it's either just the concepts or then it is ridiculously complicated unreadable trash like this here! >:-(
-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.
3
u/StoneCypher Aug 01 '20
Yeah, this isn't minified. The labels are unchanged and everything has nine character names.
This is obfuscated. They're different.
1
u/Prince_Marth Aug 01 '20
Ah yes, youâre right. Should have looked more closely. Jumped the gun.
In either case, OP, donât freak out. Normal code doesnât look like this. There are special use cases for both minified and obfuscated code. You wonât be writing this usually.
-2
u/rockstew1 Aug 01 '20
Looks minified to me
4
u/StoneCypher Aug 01 '20
Yeah, this isn't minified. The labels are unchanged and everything has nine character names.
This is obfuscated. They're different.
1
-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
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
-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
Aug 01 '20
[deleted]
157
u/levarburger Aug 01 '20
I write code like this with my sweatshirt hood up and a mask on while breaking into the NSA's secret database surrounded by 12 monitors when I'm fighting an anti-hacker in real time.
23
Aug 01 '20
Youâre not a real haxor unless those screens have scrolling bash output
17
u/outofideas555 Aug 01 '20
you also need to be an attractive female but look nerdy when you put on glasses, this way when we inevitably dress you in a tight minidress to send you undercover at a dinner party it works and the villain automatically takes the bait and falls for you
4
u/ChrysMYO Aug 01 '20
Wait, where is the part where she falls into the villains arms to plant a tracking device or lift a flashdrive?
42
u/TheVirtuoid Aug 01 '20
And all before you first cup of coffee.
30
u/atl-knh Aug 01 '20
Whatâs coffee? I only drink Jolt Cola.
6
Aug 01 '20
Whatâs that? Itâs fight milk for me all day err day.
6
1
u/__Bop Aug 02 '20
You must be a former body guard to drink the first alcoholic dairy based protein drink. I drink it every morning so I can code like a crow! Eeerrrrrr
6
u/Eklypze Aug 01 '20
My girlfriend and I hack on the same keyboard at the same time. #RelationshipGoals
2
0
u/rockdog85 Aug 01 '20
12 monitors but 24 keyboards right? 6 per hand and 6 per feet
5
u/levarburger Aug 01 '20
Of course, I'm not some peasant. I gotta keep slapping the keyboard in order to break through 15 layers of firewalls before I get intertwined with an average cop with a heart of gold, just trying to look out for himself but ends up in the wrong place at the wrong time.
-2
u/Digember Aug 01 '20
And i write code like this when I piss with one hand holding my cock and the other one using to write code.
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.