JavaScript Fundamentals Part One

My notes on Traversy Media's JavaScript Crash Course for Beginners

JAVASCRIPT

8/9/20232 min read

These notes are from the JavaScript Crash Course for Beginners.

JavaScript is a high level, interpreted programming language. It is multi-paradigm (you can write your code in several different ways like object-orientated). It is for creating interactivity on web pages. It is very fast, powerful, and easy to learn.

Getting Started

There are two methods to adding JS to a HTML file.

  1. Add it directly to the HTML by adding <script></script> to the body at the very bottom

  2. RECOMMENDED: Make a separate file by using same place as #1 but putting a src to your JS file

Variables

Variables are used to store data. You use var, let, and const. Note that var is outdated and it is better practice to use let and const.

const is used for values that cannot be change.

let is used for values that can be change.

Always use const unless you know for a fact you need to reassign the value.

Data Types

  1. String

  2. Numbers

  3. Biginit

  4. Boolean

  5. Undefined

  6. Null

  7. Symbol

  8. Object

Output: My name is Han and I am 24

This uses a string of 'Han' and a number of 24. This is then concatenated with the '+'.

Strings are written within quotations. Strings within concatenations should have spaces within the string in order to have proper spacing.

Alternatively, use the template string method for the same result.

Length Output: 12

Uppercase Output: HELLO WORLD!

Lowercase Output: hello world!

Substring: Hello

Note that JS counts 0 as 1. The substring function selected the first character (0 = H) and the fifth character (5 = o).

Apply Multiple: HELLO

Split into array: 0: "H", 1: "e", 2: "l", 3: "l", 4: "o", 5: " ", 6: "W", 7: "o", 8: "r", 9: "l", 10: "d", 11: "!"

String Methods & Properties

console.log(fruits) output: "apples, "oranges", "pears", "grapes"

It is better practice to not add a new item to the array like shown with grapes because you might not know how many items are in the array. Instead you can use push to add it to the end. The output will now display: "apples, "oranges", "pears", "grapes", "mangoes"

To add to the beginning, use unshift.

"strawberries", "apples, "oranges", "pears", "grapes", "mangoes"

To remove the last item, use pop.

"strawberries", "apples, "oranges", "pears", "grapes"

You can also check if it is an array and get the index (placement) of a given item. In this case, orange is 2.

Arrays

Arrays allow you to store multiple values within one variable.

That's it for now!

Don't forget to check out the original video! There's a completed code for it here.