con javascript

Remember console?

console.log('Hi!')

In Node, let’s try to understand what the console is. This will be interesting trip down the internals of Node, too.

Node is two things: it’s an interpreter, and JS runtime. Let’s open those two things a bit:

Interpreting means the mechanism of taking JavaScript source code, and transforming it eventually into machine code. Node really does this! Interpreter checks that a source language file conforms to the syntax standards. So if you accidentally write malformed JavaScript, either Node gives you an error, or there’s a slight bug introduced into your program.

Runtime is an environment, where you get a “process”, RAM memory, and some interfaces to the underlying actual computer that is running your program.

To inspect a JavaScript object, we can do a couple of things.

> console.log(typeof console)
Object
undefined

The typeof console is an Object. ‘typeof’ is an operator that returns a string, telling you what kind of Object it has seen.

  • typeof 5 is ‘Number’
  • typeof “thisname” is ‘string’

Let’s parse that a bit. “Object” is the base type of most all things in JavaScript. Even though this may be a bit of surprise, JavaScript is very much based on Object oriented philosophy. OO means that all things in the language form a sort of “forest” of things: a forest (not tree), because not everything can be traced to be a descendent of a ancient parent object. No. Forest leaves us the possibility to have many Parent objects.

This takes us further to the interesting feature of JavaScript.

That’s however, the topic of the next blog post. Very soon.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: