Created
May 25, 2020 05:53
-
-
Save harrisonmalone/27099b6c497c849506b900aea703f406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<script src="index.js"></script> | |
</head> | |
<body> | |
<h1>Intro to JS Lesson 👩💻</h1> | |
<p>Take a look at the console to see all of the console.logs</p> | |
<p>The line numbers will point to where the code is executing</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// printing things out | |
// console.log() | |
// variables | |
// variable declarations | |
// let, var, const | |
// by default use const | |
const hello = "hello world"; | |
// if you want to reassign a variable | |
let goodbye = "goodbye"; | |
goodbye = "bye!"; | |
// lower camel case | |
let firstName | |
let lastName | |
if (true) { | |
// block scope | |
lastName = "malone"; | |
} | |
let counter = 1; | |
while (counter < 10) { | |
// block scope | |
console.log(counter) | |
counter += 1 | |
} | |
// logic | |
let a = false || 1; | |
let b = 2 || 4; | |
let c = false && 2; | |
let d = 6 && 8; | |
// strings | |
const name = "harrison" | |
// string properties | |
name.length | |
// string methods | |
name.split("") | |
// string concatenation | |
console.log("harrison" + " " + "malone") | |
// string interpolation | |
console.log(`my name is ${name}`) | |
console.log(`We are ${50 + 50}% cool`) | |
// number | |
typeof 1 | |
// => number | |
1 / 0 | |
// => Infinity | |
const result = 0.1 + 0.2 | |
console.log(result) | |
console.log(result.toFixed(5)) | |
// operators | |
console.log(1 + 1) | |
console.log(typeof(3 / 2)) | |
console.log(2 * 4) | |
console.log(2 ** 4) | |
console.log(3 % 2) | |
// comparison operators | |
console.log(1 == "1") | |
// // => true | |
// // reason this is true is because the string "1" is being coerced into a number | |
console.log(1 !== 2) | |
// // => true | |
console.log(1 === 1) | |
// => true | |
console.log(2 < 100) | |
// => true | |
console.log(2 >= 100) | |
// => false | |
// objects | |
const myObject2 = {}; | |
// => empty object | |
const myObject3 = { | |
name: 'Harrison', | |
address: { | |
city: 'Melbourne', | |
country: 'Australia' | |
} | |
}; | |
// dot notation | |
console.log(myObject3.address.city) | |
myObject3.address = "Sydney" | |
console.log(myObject3) | |
// bracket notation | |
// const key = prompt("which data would you like to access?") | |
// console.log(myObject3[key]) | |
const myArray = [1, 2, 3] | |
myArray.push(4) | |
// functions | |
// old style but still most common way to write functions | |
// function declarations | |
function myFunc() { | |
// execute code | |
return "whats up" | |
} | |
const myResult = myFunc() | |
console.log(myResult) | |
// => "whats up" | |
function adder() { | |
return arguments["0"] + arguments["1"] | |
} | |
// console.log(adder(2, 2)) | |
function anotherFunc(arg1, arg2, ...whatever) { | |
console.log(arg1) | |
// // => 1 | |
console.log(arg2) | |
// // => 2 | |
console.log(whatever) | |
// array | |
// => [3, 4, 5, 6] | |
} | |
anotherFunc(1, 2, 3, 4, 5, 6) | |
// anonymous functions | |
const anonFunc = function() { | |
// execute code | |
return "something" | |
} | |
console.log(anonFunc()) | |
// es6 arrow functions | |
// this is what i recommend you use | |
const es6Func = () => { | |
// execute code | |
return "im in an es6 arrow function" | |
} | |
es6Func() | |
// => "im in an es6 arrow function" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment