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
// Let's take this JavaScript object and turn it into JSON | |
// Stringify should work -- it turns objects to JSON strings | |
// Parse should fail -- it turns JSON strings to objects | |
const myJavaScriptObject = { | |
dog: "π", | |
cat: "π", | |
koala: "π¨", | |
count: 3 | |
}; |
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
// Lifting State Up (React.js Example) by Dr. Derek Austin π₯³ | |
// Adapted from code by Kent C. Dodds and the React docs | |
// https://kentcdodds.com/blog/application-state-management-with-react | |
// https://reactjs.org/docs/lifting-state-up.html | |
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import "./styles.css"; |
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
// Animate 3 Card Tarot Reading by Dr. Derek Austin π₯³ | |
// Credit Paul Henckel for the original code | |
// Source: https://codesandbox.io/s/j0y0vpz59?from-embed | |
import { render } from 'react-dom' | |
import React, { useState } from 'react' | |
import { useSprings, animated, interpolate } from 'react-spring' | |
import { useGesture } from 'react-use-gesture' | |
import './styles.css' |
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
// A .csv file (comma separated values) usually won't contain any extraneous whitespace: | |
const csvManifest = | |
"William Brian,William Martin,Henry Ravens,Richard Knowles,Stephen Hopkins"; | |
// If we assume the file has no extra whitespace, there is no need to trim the strings: | |
console.log(csvManifest.split(",")); | |
// Result: ["William Brian", "William Martin", "Henry Ravens", "Richard Knowles", "Stephen Hopkins"] | |
// The following .csv file has a leading space in entries after the first one: | |
const passengerManifest = | |
"William Brian, William Martin, Henry Ravens, Richard Knowles, Stephen Hopkins"; |
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
var myFunction = function myFunction() { | |
console.log(myFunction === myFunction); | |
}; | |
myFunction(); | |
const functionTwo = () => { | |
console.log(functionTwo === functionTwo); | |
}; | |
functionTwo(); |
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
function returnAnObject() { | |
return | |
{ test: 1 }; | |
} | |
console.log(returnAnObject()); | |
function returnAnotherObject() { | |
return { test: 1 }; | |
} | |
console.log(returnAnotherObject()); |
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
console.log(Number("7") - 7 == 0); | |
console.log(Number("7") - 7 === 0); | |
console.log(Number("7") - 7 === Number("0")); | |
console.log("7" - 7 == "0"); | |
console.log("7" - 7 === "0"); |
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
console.log(Number("7") - 7 == 0); // true | |
console.log(Number("7") - 7 === 0); // true | |
console.log(Number("7") - 7 === Number("0")); // true | |
console.log("7" - 7 == "0"); // true | |
console.log("7" - 7 === "0"); // false |
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
// All permutations of falsy comparisons in JavaScript by Dr. Derek Austin π₯³ | |
console.log(false == false); // true | |
console.log(false === false); // true | |
console.log(false == 0); // true -- false, 0, and "" are loosely equal | |
console.log(false === 0); // false | |
console.log(false == ""); // true -- false, 0, and "" are loosely equal | |
console.log(false === ""); // false | |
console.log(false == null); // false | |
console.log(false === null); // false | |
console.log(false == undefined); // false |
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
const myString = " Hello world! "; | |
console.log(myString.trim()); // The leading and trailing whitespace are removed: "Hello world!" | |
console.log(myString); // The original string remains unchanged: " Hello world! " | |
// String.prototype.trim() is used with a . (dot-reference operator), not: | |
trim(myString); | |
// This would result in "ReferenceError: trim is not defined" |