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
// nested loops and multi-dimensional objects | |
// We can use nested loops to access all the elements | |
// inside multi-dimensional arrays or objects | |
let twoD = [[1, 2, 3, 4, 5, 6, 7], | |
[8, 10, 5, 7, 3, 22, 6, 42], | |
[123, 54, 12, 11, 9, 15]]; | |
let bigHero = {characters:[ | |
{name:'Hiro', voice:'Ryan Potter'}, |
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
//fetch using a Request and a Headers objects | |
//using jsonplaceholder for the data | |
const uri = 'http://jsonplaceholder.typicode.com/users'; | |
//new Request(uri) | |
//new Request(uri, options) | |
//options - method, headers, body, mode | |
//methods: GET, POST, PUT, DELETE, OPTIONS |
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
// JavaScript Event Listeners | |
// Event-driven programming: your program waits for events and uses them as triggers to run the next function(s) | |
// | |
document.addEventListener('DOMContentLoaded', init); | |
function init(){ | |
let btn = document.getElementById('btn'); | |
let lnk = document.getElementById('lnk'); | |
let txt = document.getElementById('txt'); |
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
// Unicode Characters in JavaScript | |
// Escape Sequences in JavaScript | |
// http://www.unicode.org/charts/ | |
// String.fromCharCode(num [, num, num]) | |
// myString.charCodeAt(index) | |
// \u0434 | |
// \0 \' \" \\ \n \r \t | |
// |
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
// Keyboard events in the Browser | |
//ev.char || ev.charCode || ev.which | |
// keydown keyup keypress | |
let log = console.log; | |
document.addEventListener('DOMContentLoaded', init); | |
function init(){ | |
let txt = document.getElementById('txt'); |
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
// Event Bubbling and Propagation | |
// element.addEventListener( type, func, useCapture); | |
let m = document.getElementById('m'); | |
let d = document.getElementById('d'); | |
let p = document.getElementById('p'); | |
let s = document.getElementById('s'); | |
let log = console.log; | |
let highlight = (ev)=>{ |
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
// While loops | |
// | |
// while(condition){ | |
// statements | |
// } | |
// | |
// do{ | |
// statements | |
// }while(condition) |
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
//namespace1.js | |
let STEVE = { | |
colorDiv: function(ev){ | |
let target = ev.currentTarget; | |
target.style.backgroundColor = 'purple'; | |
target.style.color = 'white'; | |
}, | |
init: function(){ | |
let divA = document.getElementById('output'); |
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
//geolocation.js | |
// How to use Navigator.geolocation | |
// | |
let G, options, spans; | |
document.addEventListener('DOMContentLoaded', init); | |
function init(){ | |
if(navigator.geolocation){ | |
let giveUp = 1000 * 30; //30 seconds |
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
// Web Storage | |
// localStorage | |
// sessionStorage | |
// JSON | |
// setItem() | |
// getItem() | |
// clear() - erase everything | |
// removeItem( key ) - delete one item | |
// key( index ) - get the name of one item |