Javascript Fundamentals #1

This is a little post after watching the second section of JavaScript: Understanding the Weird Parts by Anthony Alicea.

I want to preface this by saying that before going into the course, I didn’t think I was going to learn much about JavaScript since I’ve used it a bunch on various projects. It was true for maybe the first 15 lectures, but I am now on the 19th lecture of 85 and in those last 3 lectures, I actually learned a couple important things about the language.

  1. Hoisting – hoisting is the process in which the JavaScript syntax analyzer/parser/interpreter/compiler/whatever-it-is reads the file for functions and variables and allocates memory for said functions and variables before the analyzer actually reads the lines of code. What I mean by this is that you can call a function say callThisFunction() before callThisFunction() is actually declared. For variables, only space for the variable is allocated and it isn’t actually defined. However, you won’t get an error for not defining the variable if you call console.log(a) for variable a before it has been assigned a value.
  2. The Javascript Engine won’t look at the Event queue (click handlers, event handlers, etc.) until the execution stack is empty (until all functions and code is executed in the loading file). What I thought previously was that you could invoke an event handler before the full file is loaded. However, it makes sense that that is not the case. Obviously the whole file would have to be loaded before a click handler’s function could be called, because if that click handler’s function wasn’t already loaded, then the expected behavior wouldn’t happen right away.

Aside from these two points, I was able to review a few things about JavaScript that I had forgotten. For example ‘===’ means “strictly equal” and ‘!==’ means “not strictly equal”.

0 == false   // true
0 === false  // false, because they are of a different type
1 == "1"     // true, automatic type conversion for value only
1 === "1"    // false, because they are of a different type
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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