Help needed *Losing motivation*

This is common for beginners. Programming can have a steep learning curve and takes a while to fully understand the material.

You can’t skip the JS section, as all the other sections build off of it in some way. I’d suggest bringing out a notebook and hand writing notes for these sections. Ask on the forums what you don’t understand and don’t move on until you do.

Functions are a way of grouping code together for later. Instead re-writing the same code over and over again, you can create a function with that code and call that function everytime you need it. That is all it is, and even the core of the JS programming language is just that as you will see.

Objects are a way to store a group of functions and other information. Arrays are a object that can store basic information, while objects with key/ data pairs can store more detailed information.

Programming is based around objects.

Lets say you want to create a Array.

Let arr = [1,2,3]

When you define arr, it creates a copy of a Object known as Array in the programming language. If we go to the developer tools (F12) and console.log() what Array.prototype looks like, we see this:

image

So every array object, such as arr in this case, is a child object of the parent Array object in the programming language. Since all the functions such as length, keys, find, etc are stored in the prototype of Array, every single new child array object that is declared (arr) have access to these functions.

So when you say arr.push(value), arr just asks the parent Array object for what .push(value) is, and the Array object provides it. arr itself doesn’t store all of the push, pop, etc functions, it just stored a reference of were to look for them in the parent object Array.

Now you might be getting confused with what the word Object means. Isn’t this a Object?

let obj = {
 "Name": "Bob"
}

Well in this case this is also a Object, but instead of referencing Array.prototype, it references Object.prototype due to the way you declared with key/ data pairs!

image

obj in this case is the child object of the parent Object in the programming language (capital O), same with arr is a child object of a parent object called Array in the programming language.

Array and Object are very close to each other, because both store information, just in a slightly different way. They even share some of the prototype functions.

The term constructor that you may see is the act of creating a child object from a parent object. For example, when we created arr, it activated Array’s constructor, known as Array.prototype, and creating a reference to it.

The same is true with console.

console.log("Hello World")

When you look at what console is in the programming language, its just another object. In this case however, you don’t create a new console object and store it in a variable. Its stand alone and already declared for use.

image
(Notice log and clear)

Same is even true with String, and Number, and anything else you can think of.

image

Every string you create is a child object of String.prototype, and every number is a child object of Number.prototype. That is where everything gets its functions from. Every string you make is a object and every number is also a object.

The use of these objects is object oriented programming. You can create your own custom object prototypes that all instances of that object share, and even modify the Array and Object (etc) prototypes.

Most of this is discussed in Object Oriented Programming and Functional Programming. I am just giving you a very brief look into what programming really comes down to. All a programming language is a collection of these Objects that you can access and use their functions. Some languages have different functions stored within these parent Objects, while others use completely different Objects for different purposes.

I hope this helps you understand what the core concept of programming is.

1 Like