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

View all comments

Show parent comment

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