September 14, 2022
To explain the relationship of JavaScript to HTML and CSS in simple terms is that HTML is the structure of the webpage, CSS is what we use to style or beautify the structure and JavaScript is the one responsible for the “action” that happens in the webpage. A simple analogy that I can think of for their relationship is an event. Let’s look at a wedding event for example. It involves the plan, the decorations or activities and its coordinator. The HTML would be the plan, as it will serve as the structure as to how the wedding party will be, then the CSS will be the decorations and activities that will make the event beautiful and memorable. In order for the event to be functioning well on the day, we would need the coordinator to pull all the strings needed to make the event successful. The guests or users if we think of the browser will not enjoy all these if not for the commands and actions done by the coordinator.
Control Flow is how the computer specifies the sequence in which a code executes, usually in a top-down manner, unless the code control changes its course when it meets with other structures. One example is the loops. A loop is a conditional statement that repeats the given task until the given condition is met. Let’s think of baking and icing a birthday cake. We would need to follow instructions on how to bake a cake and we will continue icing it until we reach our desired look on the cake.
The Document Object Model is a platform and interface that allows programmers to access and update the content, structure and style of a document. It means to interact with objects in an HTML document. Manipulating the DOM will allow you to modify elements, add, delete or style them without a refresh. There are a lot of methods & properties that can be used for DOM manipulation. Please refer to this link w3schools for a detailed explanation of all these.
Objects and arrays are both used to store data. Objects is a special data type that is used to store a collection of data and is mutable. Arrays on the other hand are special type of variables that are used to store a list of values and that are also mutable.
When to use Objects?
Objects represent a “thing” in your code, anything that is made up, for example, a person or a car that can be defined by a set of characteristics called properties. It consists of a key and value.
When to use Arrays?
We use arrays when we want to create and store a list of multiple items in a single variable. It is especially useful if we want to create a list of items that can be accessed by their numerical position in the list.
A function is a set of code that programmers use that are designed to perform a particular task. A JavaScript function can only be executed when you “call” it (something that invokes it). It is helpful because you can use the function code over and over again, rather than writing it multiple times. Also it enables programmers to breakdown a problem into smaller pieces, each of which performs a particular task.