Javascript Learning

Going back to the super basics to build up from there with JavaScript, the Definitive Guide

by db_dev

HTML

<script src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div>Everything is in the console.</div>

JavaScript

// Characters can be held in strings
let name = "スロック"
console.log(name);

// Some Math
console.log(Math.pow(2, 53));

// Convert Bool to String
let myBool = true.toString();

// Remove duplicates from array easily
let raw = [1, 2, 3, 4, 5, 8, 9, 1, 2, 7, 9, 1, 6, 2, 3];
let raws = [...raw];
console.log([...new Set(raws)]);

// Another way to create an Array
let array1 = new Array(); //empty
let sinclinePilots = new Array(6); //empty with places

//Add to Array
sinclinePilots[0] = "Lotor";
sinclinePilots[1] = "Acxa";
sinclinePilots[2] = "Narti";
sinclinePilots[3] = "Ezor";
sinclinePilots[4] = "Zethrid";
sinclinePilots[5] = "Empty Seat";

delete sinclinePilots[5]; // Empties this seat, but doesn't remove the place

// Create Array with elements
let voltronPilots = new Array("Shiro", "Keith", "Lance", "Pidge", "Hunk");
//voltronPilots.contains("Shiro"); // Does this contain Shiro? True!

//Lion Shifting!
voltronPilots[2] = "Allura";
voltronPilots[1] = "Lance";
voltronPilots[0] = "Keith";

// Another way to create an Array E6
Array.of(); // [] Empty
Array.of(10); // [10] Single number
Array.of(1, 2,3); // [1,2,3]

// Make a copy E6 - copies the original and is affected by the original
let copy = Array.from(voltronPilots);