>> Example file name: main.js
This is a generic variable keyword.
let will assign a variable just like
var, but with slightly different behavior. It mostly differs by creating “block level scope”.
This is a variable that cannot be changed. It is short for “constant”.
Primitive Data Types (Strings, Numbers, Booleans)
A string is a block of text. These blocks of text are always defined with quotation marks, whether single or double.
Numbers do NOT have quotes around them. They can be negative as well.
Properties and Methods
Data types have built-in functionality known as
methods. These extend the functionality so that we can gather information about, or manipulate the types. We will access both properties and methods using the
dot notation. First, we provide the name of the variable, a dot, then the name of the property or method.
With properties, we can access data from our data types. There are many different properties on every data type. Below, we are trying to access the length property of a string. By finding the length, it will tell us how many characters are in the string.
Methods are different from properties because they are followed with parenthesis. Take a look below at the .toString() method. It will convert a number or Boolean to a string.
With functions, we can perform a variety of actions in order to return a final product. Fun fact: Methods are a type of function!
Functions always begin with the function keyword. This lets whatever is running your program know what it is and to treat it as such. Then, comes the actual name of the function, followed by open/close parenthesis and brackets. All of our code for the function resides between the brackets.
As seen above, I have declared a function (logsHelloWorld) and then set it up to console.log ‘hello world’. In order to make this function run, I needed to write the function’s name again, followed by parenthesis after the brackets were closed. This is the syntax used to run a function.