JavaScript Basics

How does JavaScript compare to HTML and CSS?

HTML is the structure, CSS is the style, and JavaScript is what brings the site to life. JavaScript enables your website to be interactive by responding to the user. For example the the total price of your online shopping cart, could be the result of JavaScript. As you add or remove items from your cart, the price will change, and JavaScript code is the reason for this.


What is control flow? What is a loop?

  • Control Flow is the flow of code from one step to the next. Each step will run based on a set condition. If the specified condition is not met, another step will be executed.
  • Going Outside
    • Is it raining?
      • Yes - take umbrella
      • No - leave the umbrella at home
  • Loops are a block of code that will run until a desired outcome is reached.
  • Flipping a Coin
    • Does the flipped coin show heads?
      • Yes - flip the coin again
      • No - stop flipping, because tails is cool.

How is acessing data in an Array different than an accessing data in an Object?

To access data in an array you must call on the index of the data that you want. For example someArray[2], this will call on the third value of the array. It is the third because JavaScript is 0 indexed, therefore the first value in an array has an index of 0. To access data in an object we need to call on the values 'key'. For example someObject['age'] or SomeObject.age, will both return the value of the key 'age' that is stored in someObject. Essentially arrays are lists of values and each value can be called upon by its place in the list. And objects are unordered lists that contain keys. Calling on the keys allow us to access the stored value.


What are functions and why are they useful

Functions are a lines of code, written with empty variables. By assigning variables to the function we will recieve our result. This allows us to write one function, and call upon it as many times as we like and with different variables and recieve our results. For example addFunction(x,y) returns the value of x+y. We can then write addFunction(22,28), addFunction(999+20), addFunction('Hello ', 'World'), and we will receive 50, 1019, and 'Hello World', respectively.

a coffee cup and saucer.