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
console.log(typeof 37) // "number"
console.log(typeof 2.71828) // "number"
console.log(typeof Math.E) // "number"
console.log(typeof Infinity) // "number"
// The typeof NaN is "number" even though NaN means "Not-A-Number":
console.log(typeof NaN) // "number"
// Calling Number explicitly is one way to parse a number:
console.log(typeof Number(`1`)) // "number"
console.log("Hello world!".padStart(20))
console.log("Goodnight moon!".padStart(20))
// Output:
// Hello world!
// Goodnight moon!
"Pizza".padEnd(30,".")+"$19.99"
// "Pizza.........................$19.99"
const menuItem = (item, price) => item+price.padStart(40-item.length,".")
console.log(menuItem("Pizza","$19.99"))
console.log(menuItem("Soda","$2.99"))
console.log(menuItem("Greek Salad","$9.99"))
// Output:
// Pizza.............................$19.99
// Soda...............................$2.99
// Greek Salad........................$9.99
import React, { useState } from "react"
import ReactDOM from "react-dom"
import "./styles.css"
function App() {
// React Hooks declarations
const [searches, setSearches] = useState([])
const [query, setQuery] = useState("")
import React, { useState } from "react"
import ReactDOM from "react-dom"
function App() {
// React Hooks declarations
const [searches, setSearches] = useState([])
const [query, setQuery] = useState("")
const handleClick = () => {
// Save search term state to React Hooks
let array = ["😜"]
array.push("πŸ˜‚")
console.log(array) // Array [ "😜", "πŸ˜‚" ]
setSearches([query].concat(searches)) // prepend to React State
/**
* First checks typeof, then self-equality to make sure it is
* not NaN, then to make sure it is not Infinity or -Infinity.
*
* @param {*} value - The value to check
* @return {boolean} Whether that value is a number
*/
const isNumber = value => {
// First: Check typeof and make sure it returns number
// This code coerces neither booleans nor strings to numbers,
/**
* Check whether the value is a JavaScript number.
*
* First checks typeof, then self-equality to make sure it is
* not NaN, then for equality to Infinity or -Infinity.
*
* @param {*} value - The value to check
* @return {boolean} Whether that value is a number
*/
const isNumber = value => typeof value === 'number' && value === value && value !== Infinity && value !== -Infinity