if / else replacement
Longhand:
const x = 20;
let answer;
if (x > 10) {
answer = "greater than 10";
share your perspective and keep it short and sweet, two sentences at most
justify your view, One or two bullets but not more than three or you lose your audience
Show an example, personal experience or evidence to support your reasoning
import { useState, useEffect } from "react"; | |
const CACHE = {}; | |
export default function useStaleRefresh(url, defaultValue = []) { | |
const [data, setData] = useState(defaultValue); | |
const [isLoading, setLoading] = useState(true); | |
useEffect(() => { | |
// cacheID is how a cache is identified against a unique request | |
const cacheID = url; |
// iPad model checks. | |
const getiPadModel = () => { | |
if (window.screen.height / window.screen.width == 1024 / 768) { | |
// iPad, iPad 2, iPad Mini | |
if (window.devicePixelRatio == 1) { | |
return "iPad 1, iPad 2, iPad Mini 1"; | |
} | |
// iPad 3, 4, 5, Mini 2, Mini 3, Mini 4, Air, Air 2, Pro 9.7 | |
else { | |
return "iPad 3, iPad 4, iPad 5, iPad Air 1, iPad Air 2, iPad Mini 2, iPad Mini 3, iPad Mini 4, iPad Pro 9.7"; |
let subscribers = {}; | |
module.exports = { | |
// method to publish an update | |
publish(event, data) { | |
if (!subscribers[event]) return; | |
subscribers[event].forEach(subscriberCallback => | |
subscriberCallback(data)); | |
}, | |
// method to subscribe an update | |
subscribe(event, callback) { |
let fs = window.RequestFileSystem || window.webkitRequestFileSystem; | |
if (!fs) { | |
console.log("check failed?"); | |
} else { | |
fs(window.TEMPORARY, | |
100, | |
console.log.bind(console, "not in incognito mode"), | |
console.log.bind(console, "incognito mode")); | |
} |
function deferStartTillUserAction(cb) { | |
var locked = true; | |
var didClick = false; | |
var didScroll = false; | |
function unlock() { | |
if (locked) { | |
locked = false; | |
cb(); | |
} |
let regex; | |
/* matching a specific string */ | |
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello" | |
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO" | |
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes... | |
/* wildcards */ | |
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo" | |
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo" |