r/learnjavascript • • 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😅

Post image
208 Upvotes

105 comments sorted by

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.

96

u/mypetocean Aug 01 '20

With variable names like Aakaanksha_0x5dbd and Aakaanksha_0x4082, this isn't minified — this is obfuscated.

This is done to hide the algorithm: common both in malware and in code which a company wants to try to protect for reasons of IP or pirating.

26

u/codecommentgold Aug 01 '20

Aakaanksha is a female Indian name.

40

u/alexxxor Aug 02 '20

I believe 0x5dbd and 0x4082 are popular surnames too.

8

u/ciaisi Aug 02 '20

Don't give Elon Musk any ideas

3

u/J_Peanut Aug 01 '20

Well, it is also more often than not done for fun - I have a C background and obfuscating code is seen as a fun challenge. The security through obscurity is pretty much dead in the C world, so it is seldomly used. C code that relies on security through obscurity exists, but this is mainly old code or a very weird decision.

1

u/JohnLocke84 Aug 02 '20

What are you talking about ? , you don’t write the variables like that 🤔🤔

const π__0x789 :number = 3.1416
const ultra__uselessOff_0x00 : string = 'Off'

console.log(`Sarcasm: ${ultra__uselessOff_0x00}`)
console.log(`Where d f%^*#* are the Tuples in JS, useless variable: ${π__0x789}`)

1

u/mypetocean Aug 02 '20

/unjerk

Interestingly enough, tuples are at Stage 2 in TC39, as deeply immutable primitive-and-tuple-only containers compared deeply by their contents rather than their identity.

1

u/JohnLocke84 Aug 02 '20

/SarcasmOn Typescript /SarcasmOff

let arrayAny : any[] = ['JS', 4 , 'DataScience']

let tuple: [string, number] = ['Typscrypt' , 4, 'Tensorflow']

And that would be super cool

1

u/Ex_Minstrel_Serf-Ant Aug 05 '26

I would say it's doing both. The obfuscation makes some of the identifiers longer, which would make the file bigger. To help counteract this, there is some minifying taking place in terms of removing all unnecessary whitespace from the document.

9

u/densch92 Aug 01 '20

is there an actual way to "maxify" things too?
sure comments are lost, that's clear.

but there must be certain rules how stuff is put into a minified form. so shouldnt the other way be possible too?

32

u/TheVirtuoid Aug 01 '20

You have tools like the "Prettify" button in Chrome's dev tools that will make a good attempt at making the code "look" better. However, depending upon the level of sophistication of the minifier / obfuscater, this may not yield you much.

One example: A minifier will rename variables. If you had a variable named "MyCharacterIcon", it may rename it to something like "a". Without source maps, there is no way a prettifier can know that "a" means "MyCharacterIcon".

Having said that, though, using tools like "Prettify" to investigate source code is a good learning tool, as long as you can keep track of where you are.

1

u/ampersand355 Aug 01 '20

I understand the necessity for things like that but it's unfortunate for people who want to understand or learn new things.

3

u/HeinousTugboat Aug 01 '20

If it's just minified and not obfuscated like OP, there will be strings where the code interfaces with the user, like DOM elements or input/output strings. You can use a code formatter (both Firefox and Chrome dev tools have one in browser you can use) to clean it up, then follow the function calls. You could also pull it into an IDE that can do symbol renaming and just change them to names for yourself.

7

u/JamesWilsonCodes Aug 01 '20

If the process includes a source map, browser devtools can see the original code :)

1

u/kevintootill Aug 01 '20

If you open the dev console you can restore minimized js back to the original formatting

8

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.

This is easily reversed, but an unminifier won't succeed

0

u/[deleted] Aug 01 '20

[deleted]

1

u/StoneCypher Aug 01 '20

this produces larger source than the input, and is missing all basic minification steps other than whitespace removal. this is not minification

2

u/PM_ME_A_WEBSITE_IDEA Aug 01 '20

I mean, does it speed processing up, or does it save in bandwidth? Isn't the point just to have small bundles for best loading performance?

3

u/HeinousTugboat Aug 01 '20

Minification supports network speeds. It can reduce a JS file by a pretty hefty amount. Obfuscation doesn't. Obfuscation just makes it harder to trace what the code is doing.

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 const and let. 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

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.

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

u/Orkaad Aug 02 '20

Always has been.

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

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

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

-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

u/[deleted] Aug 01 '20

It's actually been obfuscated. Not the same thing.

Apparently everyone in this subreddit thinks they are the same thing.

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/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

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

u/[deleted] 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

u/StoneCypher Aug 01 '20

thank you, that was my goal

2

u/[deleted] Aug 01 '20

No problem, I have joined the efforts below 😅

-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

u/[deleted] 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

u/[deleted] 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.

-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]

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

u/[deleted] 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

u/[deleted] Aug 01 '20

What’s that? It’s fight milk for me all day err day.

6

u/TylerDurdenRockz Aug 01 '20

What's that? Its Bomb Jager for me all day erryday

1

u/__Bop Aug 02 '20

You should try wolf cola. Wolf cola, everyone...

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

u/Ferdelva Aug 02 '20

Without ever touching the mouse, not once

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.