Skip to content

Instantly share code, notes, and snippets.

View djD-REK's full-sized avatar
🌞
Full-Stack JavaScript Developer & Doctor of Physical Therapy 🌞

Dr. Derek Austin djD-REK

🌞
Full-Stack JavaScript Developer & Doctor of Physical Therapy 🌞
View GitHub Profile
// 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
};
// 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";
// 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'
// 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";
var myFunction = function myFunction() {
console.log(myFunction === myFunction);
};
myFunction();
const functionTwo = () => {
console.log(functionTwo === functionTwo);
};
functionTwo();
function returnAnObject() {
return
{ test: 1 };
}
console.log(returnAnObject());
function returnAnotherObject() {
return { test: 1 };
}
console.log(returnAnotherObject());
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");
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
// 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
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"