Parallels Between C and Javascript

I’ve been using javascript for a while now. I say use instead of write because initially, it was copying and pasting scripts from across the web into my static html files, crossing my fingers, and hitting refresh. Over the years, I’ve grown pretty competent with javascript and particularly jQuery(ui/mobile), and have begun experimenting with some clientside MVCs like Backbone.js.

So far so good, pretty typical story for a web developer. As part of my Computer Science minor from Maryland, I have to take and pass a class on C and assembly next semester. I’ve heard brutal things about this class, so I’m attempting to get a leg up by learning C over the summer. I’ve been following along Learn C The Hard Way at a slow enough pace that I don’t overwhelm myself, and what I learn will actually be relevant to the class.

As I begin to grasp C, I’ve come up with some pieces that remind me of javascript. I guess this shouldn’t shock me because their syntaxes are already similar, but alas I felt compared to share.

In javascript, you quickly learn to avoid global variables, as they are bound essentially to the browser, and can become referenced (incorrectly) by other scripts on the page. Meanwhile in C, your variables are kind of bound to the CPU itself, literally just wasting memory if left untouched.

In C, you access the computer’s hardware and directly interact with it. Similarly, in javascript (which was built for the web after all), you directly access and can manipulate the browser’s DOM.

I had previously read people comparing javascript to a low-level assembly like language for the web. I didn’t really understand this. I felt comfortable writing javascript, and things like assembly and C are still scary for me. I now understand the comparison and would have to agree to an extent. Within the browser, javascript is a low-level language (discounting the code for the browser itself). Countless frameworks and modern workflows with in-browser tools have helped alleviate this reality, but it still exists.

I already feel as though I’ve tackled at least a good deal of javascript at this point. Hopefully I will be able to replicate my success with C, outside the browser and into the processor.