DEV Community

loading...
Cover image for Day 3: Why is JavaScript so...savage ?

Day 3: Why is JavaScript so...savage ?

oreoyona
・Updated on ・1 min read

The day started extremely well, I began with Brian Tracy's best seller, *The Power of Self Discipline * and following the advices of the book, I set my goals for my day:

  1. Studying at least 5hours for my tomorrow exam

  2. Learn JavaScript with freecodecamp for 2hours

  3. Build my own project using HTML, CSS and JavaScript

The exam I am preparing is Psychiatry and after 5 good and exhausting hours of deep work(thank Cal Newport) I finished and achieved my today's goal.

I then after began to code with freecodecamp(RegEx) and I did pretty well at the start but the overall feeling was: Why the heck is JavaScript so hard ? So savage ?
Why are RegEx even existing ?(Rhetoric question of course)

I needed to cry so bad but I refused to use another excuse of not coding so, I decided that I was gonna build my project.

As you can figure, I am not building it, I am writing this blog instead. Why ? I feel extremely tired, exhausted. The 2 hours of coding I spent on freeCodecamp learning about RegEx took all my energy and the apathy I'm feeling now is just...

Why is JavaScript so hard?
It's 22:40 in my country but I need to be loyal to myself so I am gonna build a login form and use some RegEx to add interactivity to it.

I knew that the road would be tough, but I chose it and I am not gonna miss my target.

I will master that language because I can!(right?)

Discussion (5)

Collapse
ehaynes99 profile image
Eric Haynes

Just to clarify, regexes exist in every modern programming language, not just javascript. They're often permitted in shell commands and even configuration files for many utilities. While there are some differences between their engines, the vast majority of use cases will have the same syntax across platforms. It's a great skill learn at least at a basic level.

They're even commonly used in IDEs and text editors (E.g. in vscode, in the find/replace dialog, there is a .* button that enables regex). This can get REALLY powerful when you need to make a change to a large number of similar but different values.

For example, let's say you copy/paste a table from a browser, you'll get something like:

first   one
second  two
third   three
Enter fullscreen mode Exit fullscreen mode

If you want to convert it to a block of JSON, you could spend an hour surrounding the keys and values with quotes, and replacing the tab with :. OR, you can use find with:

([^\t]+)\t(.*)
Enter fullscreen mode Exit fullscreen mode

which says: "find a group of stuff that is not a tab (group 1), followed by a tab, followed by the rest of the line (group 2)".

Then replace with:

  "$1": "$2",
Enter fullscreen mode Exit fullscreen mode

which says:

  • two spaces and a quote (")
  • whatever was in group 1
  • quote, colon, space, quote (": ")
  • whatever was in group 2
  • quote, comma (",)

Presto!

  "first": "one",
  "second": "two",
  "third": "three",
Enter fullscreen mode Exit fullscreen mode

Now you have 59 extra minutes. ;)

Collapse
jmfayard profile image
Jean-Michel Fayard πŸ‡«πŸ‡·πŸ‡©πŸ‡ͺπŸ‡¬πŸ‡§πŸ‡ͺπŸ‡ΈπŸ‡¨πŸ‡΄ • Edited

Hello oreoyona, it is normal to feel stuck and frustratetd. That says nothing bad about you. It still get stuck and frustrated after many years of programming. What feeling stuck means is that a particular approach you choose (damn regex!) didn't work out and you want to try out a new one.

One tip I have is to learn a language by writing unit tests

Collapse
oreoyona profile image
oreoyona Author

Thank, I'll try that. Seems interesting

Collapse
sargalias profile image
Spyros Argalias

JavaScript isn't too difficult of a language. But anything can feel difficult if you don't have learning resources that go at a good pace for you.

In particular, I would say free code camp is great for practice, but not good for learning. It doesn't give you enough background and understanding on how everything works together.

It may be beneficial for you to look at some courses and continue with Free Code Camp for practice only. Some examples are The modern JavaScript bootcamp or MDN's tutorials on JavaScript. Even if someone does both of those courses, they will still need more practice or to potentially repeat them.

Keep going, it's a marathon, not a sprint :).

Collapse
oreoyona profile image
oreoyona Author

Thank you for your recommendations, I really appreciate