Every Snowflake Looks Exactly Alike from the Right Distance

1000 Nerds Are Sharpening Their Bat’leths

For today’s blog we were tasked with the task of explaining the differences between some things. On researching, I discovered that these are pretty common interview questions, so I looked it up.

1: Find rabbit hole

2: Dive in.

F’rinstance: What is the difference between: function Person(){}, var person = Person(), and var person = new Person()?

Like snowflakes, from a distance they can appear to be the same thing, but as our new friend Rlyn Ben explains in his extremely concise blog post:

function Person() {}

Function Declaration
Code above declares a function statement (statements perform an action) but does not execute, however, it does get registered into the global namespace.

var person = Person()

Function Expression
A variable ‘var person’ has been defined and contains a value reference to a Person function. Any JavaScript Expressions (including Function Expressions) always returns a value. This may also be an Anonymous function if no name has been assign to a function but wrapped in parenthesis to be interpreted as an expression.

var person = new Person()

Function Constructor
By adding the keyword ‘new’. We are instantiating a new object of the Person class constructor. A function declaration is just a regular function unless it has been instantiated, it then becomes a class constructor.

So the snowflakes do appear to be a little different on closer examination. But what about this one: What is the difference between attribute and property?

On that one, the snowflakes seem to be just far enough away to not only look alike, but to cause dissension among the ranks of the people from different distances. Here’s the number one answer, from StackOverflow user Alnitak:

In general terms (and in normal English usage) the terms mean the same thing.

In the specific context of HTML / Javascript the terms get confused because the HTML representation of a DOM element has attributes (that being the term used in XML for the key/value pairs contained within a tag) but when represented as a JavaScript object those attributes appear as object properties.

To further confuse things, changes to the properties will typically update the attributes.

For example, changing the element.href property will update the href attribute on the element, and that'll be reflected in a call to element.getAttribute('href').

However if you subsequently read that property, it will have been normalised to an absolute URL, even though the attribute might be a relative URL!

The next question was simple: What is the difference between call stack and task queue?

And, again, SO has the solution!

A job queue (sometimes batch queue), is a data structure maintained by job scheduler software containing jobs to run.

https://en.wikipedia.org/wiki/Job_queue

A call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, control stack, run-time stack, or machine stack, and is often shortened to just "the stack".

https://en.wikipedia.org/wiki/Call_stack

So in short, a job queue is a queue of things to do (usually stored persistant) and a call stack is a stack of routines.

A job would have variables assigned to it, and a call stack would be the abstract implementation.

So a job could "call" a method from a call stack.

Which is why they specifically tell you that the needle is in a hay stack, not a wheat or barley stack. Those are different.

The last question was even more snowflakey: What are the differences between ES6 class and ES5 function constructors?

Bestinterviewquestion.com suggests:

ES5 Function constructors work and look the same but the main difference is observed when the developer uses the Inheritance property. … ES6 class allows the developers to instantiate objects using the new operator. ES5 function constructors focus on how the objects are instantiated.

While for the most part, people seem to agree on this one point:

It’s fun to know the real struggle we used to have in the past when there was no class keyword or at least it was not being supported widely and I remember using this keyword and prototype everywhere in my earlier Javascript days.

Speaking as someone who has had a bulletin-board hanging on the wall like some crazed conspiracy-theorist, with a bunch of yarn strings connecting different sections of code together trying to track the elusive Mr (this), that is an improvement, even though most people seem to agree that the new ES6 syntax is just a sugarization of the same ES5 functionality via the class keyword.

Is this this this or is this that this?

It all just depends on how closely you want to peer at the snowflake, or if, from your relative proximity, there is a difference between Star Wars and Star Trek.

Or to reiterate:

“I am your father, Captain Kirk” - M. Scott — D. Vader

--

--

4a 75 73 74 20 61 6e 6f 74 68 65 72 20 63 6f 6d 70 75 74 65 72 20 6e 65 72 64 20 77 69 74 68 20 61 20 62 6c 6f 67

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
crashdaddy

4a 75 73 74 20 61 6e 6f 74 68 65 72 20 63 6f 6d 70 75 74 65 72 20 6e 65 72 64 20 77 69 74 68 20 61 20 62 6c 6f 67