What is Javascript?
and why do we use it.
Dubbed as the 'language of the web', it is what allows interactivity between user and product(website or app).
Examples are but not limited to: showing a side bar at the click of a button, playing audio and video in a web page, or displaying animations that look really cool!
What you can see below is the html code for my navigation bar in this page.
Underlined are the javascript functions where if a user interacts with the button by clicking it, triggers the function.
But what is the function? What does it do if I click it? That is what is decided in Javascript as can be seen in the code below
This function, although coded with the intention to bring out the side bar by pushing the main content to the right
(idk what happened but at a certain point i chose not to die on that hill), pulls out the side nav bar from the shadow realm and presents it to you
at the click of the "more" button
Having seen this example, I ask you to indulge me with this analogy; HTML and CSS is what makes a robot look like a robot,
javascript is a processing chip decides what the robot does when given stimuli.
This robot is very methodical, it goes step by step unless instructed otherwise; this is what is known as Control flow
You can even tell the robot to go over different steps or information, set how many times it goes through that information,
and even make it go through the information in perpetuity, this is called a loop.
The DOM
With a name so ominous, I was mildly irked that all it meant was Document Object Model.
Building on the analogy, the DOM is like the blueprint for the whole robot, from its retractable claws to its laser vision.
Knowing this, you can now change the robot's appearance just by telling the processing chip what you want.
Objects and Arrays
Now say the robots arm was an object, all the information pertaining to the robotic arm such as
retracted length, full length, density etc. are stored within the processing chip.
To access the information and change it within the chip you can use "[]" or '.' commands.
An array is a type of object, an empty space that has the potential to infinitely expand on itself, and can contain anything you ever want.
This robot and the entire universe could exist within an array;
lets not get too bogged down on that
But arrays are not entirely straight forward, seeing as it counts from 0. Say an array has [The universe, the robot, me],
I want to access me, so I must interact with the array using [2] not [3]
Worry not, typing that out confused me too. I guess that's what happens when you build a processing chip for a robot
in under 2 weeks; Thanks Brendan!