Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
35 changes: 35 additions & 0 deletions 01-Fundamentals-Part-1/starter/1-Values&Variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
let js = "amazing";
console.log(40 + 23 + 8 - 10);

console.log("Adam");
console.log(23);

let firstName = "Adam";
console.log(firstName);


// Conventions for naming variables in JS.
// You should stick to using camel case -- example:
let camelCaseVariable = "testing";
// notice how the first letter is lowercase but then the first letter of every subsequent word is capitalized. That is the standard/convention in JS

// Here are some hard rules of how you cannot name variable names in JS: variables can't start with a number -- example:
// let 3years = 3; // This will cause an error

// Variable names can only contain letters, numbers, underscores, and the dollar sign ($).
// another example -- the variable name below will throw an error:
// let adam&jess = "spouses";

// Variable names can't be reserved keywords that JavaScript already uses. Examples would be "new", "this", and "function"

// One odd case is naming a variable name. Sometimes this is used as a reserved keyword, but JS will still allow you to assign a variable as "name". To play it safe don't assign a variable to "name" though
let name = "Layla";

// Another convention is that you shouldn't start a variable name with an uppsercase letter. It's not going to cause an error it's just that in JS you typically start a variable name with an uppercase letter for specific use cases, such as object oriented programming (e.g. classes).

// Variables that are in all caps are reserved for constants that we know will never change.
// Example:
let PI = 3.14159;

// Final convention for variable names is to make sure that they are descriptive

45 changes: 45 additions & 0 deletions 01-Fundamentals-Part-1/starter/2-DataTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
In JavaScript every value is either an object or a primitive.

In JS there are 7 primitive data types
*/

// 1. Numbers -- Floating point numbers --> used for decimals and integers. These numbers always have decimals even if we don't see them and don't define them.
let age = 23;

// 2. Strings -- sequence of characters --> used for text
let firstName = "Adam";

// 3. Boolean -- Logical type that can only be true or false --> Used for making decisions
let fullAge = true;

// 4. Undefinded -- Value taken by any variable that is not yet defined "empty value"
let children;
console.log(`The variable "children" is of type: ${typeof children}`);

// 5. Null -- empty value, but it's used in different circumstances

// 6. Symbol -- Introduced in ES2015 -- A value that is unique and cannot be changed

// 7. BigInt -- Introduced in ES2020 -- Larger integers that the Number type can't hold


/*
JavaScript has a feature called dynamic typing: We do not have to manually define the data type of a value stored in a variable when we declare it. Instead variable types are determined automatically.

The distinction between a value and a variable is important. In JavaScript it's the value that holds the data type not the variable.
*/

// Another important implication of dynamic typing is that later in our code we can assign a new value with a different data type to the same variable without a problem. Example below
let x = 10;
x = "I changed to a string";
// this can sometimes be very useful but it can also be the source of some tricky bugs

// The typeof operator can be used to determine the data type of a variable or a value
console.log(typeof 23);
let testBoolean = false;
console.log(typeof testBoolean);
console.log(typeof "this is a string");

// there is a error that exists in the typeof operator. The below line of code will print that null is of type "object"
console.log(typeof null);
13 changes: 13 additions & 0 deletions 01-Fundamentals-Part-1/starter/3-LetConst&Var.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// there are three different ways to declare variables in JS. let, const, and var

// we use the let keyword to define variables that may change later
let age = 30;
age = 31;
// in technical terms we call this reassigning the value of a variable or mutating it


// we use the const variable when we define variables that are never meant to change. const creates an immutable variable
const birthYear = 1995;
// if we try to reassign this an error will be thrown: "assignment to constant valuable"
// since variables defined with const are immutable this also means that we cannot define an empty const variable
// const age; // error: const declarations must be initialized
2 changes: 2 additions & 0 deletions 01-Fundamentals-Part-1/starter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
</head>
<body>
<h1>JavaScript Fundamentals – Part 1</h1>

<script src="0-script.js"></script>
</body>
</html>