Learning More Advanced Code: Leveling up my JavaScript

This week, even though every day felt like a Monday…

I have been working on creating the habit of writing out a code plan, including pseudo-code prior to tackling a problem. This week it included a series of post-it notes to really play through the game Towers of Hanoi to really understand the rules and to work through the game logic.

I talked this out with my coding network, and it was reassuring that even senior developers sometimes need to sketch out a problem before even writing their pseudo-code.

Image by Slon on Pixabay: https://pixabay.com/users/www_slon_pics-5203613/

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

function Person() {}

Declares a named function but does not execute it. It can be called at a later point using Person(); . In JavaScript, you need to declare a function, but you can use it prior to it being declared.

var person = Person()

Declares a new function called Person. It also uses (invokes) it. Then, it assigns the return value to the variable person.

var person = new Person()

This is an example of an object constructor function, meaning it is the initiation of the new keyword. In this case, it returns a new object instance. The value of “person” in this example is an object.

What’s the difference between an “attribute” and a “property”?

An attributes refers to additional information of an object, while properties are describing the characteristics of an object.

https://javascript.info/dom-attributes-and-properties

What language constructions do you use for iterating over object properties and array items?

I regularly use for loops, but have also been researching and playing with Transformation methods. The transformation methods I have been working through learning are map() and filter(). These I can see being useful to quickly search a series of arrays for testing and QA.

This video link was helpful for introducing me to Transformation methods (along with other helpful methods):

https://www.youtube.com/watch?v=R8rmfD9Y5-c&t=81s

What is the event loop?

JavaScript operates on a single thread. Browser API’s make it appear like a multi-threading language. The event loop enables the process of asynchronous development.

The event loop continuously checks if the call stack is empty. If empty, new functions are added from the event queue. If it is not, then the current function call is processed.

Essentially, the event loop is what is moving our code through the code and ensuring everything is run until all functions are called and executed.

A great explanation (with diagrams) is on this website:

https://flaviocopes.com/javascript-event-loop/

What is the difference between call stack and task queue?

The call stack keeps track of all operations in line to be executed. Whenever a function is finished, it is popped from the stack.

The event queue sends new functions into the track (or queue) for processing. It follows the data structure to maintain the correct sequence in which all operations should be sent for execution.

What are the differences between ES6 classes and ES5 function constructors?

ES6 Classes:

· Defines new object and appends functions to prototype

· Considered as syntax base for constructor functions

· Allows developers to instantiate objects using new operator

· Ensure the keyword which is basically used inside the class only refers to the object that is being created by the developer

ES5 Function Constructors:

· Can only be executed with the help of a new operator

· Focuses on how the objects are instantiated

· Focuses on implementing the reusable object creation code

· Any function can be used as a constructor

Even though this post is a little drier than my normal, well, it’s been a 7 day series of Mondays this past week. However, I plan to keep pushing through, learning more about DRY’ing up my code and attempt to put these more advanced concepts into practice.

Your friend in code,

Rachel

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