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(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" |
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("Hello world!".padStart(20)) | |
console.log("Goodnight moon!".padStart(20)) | |
// Output: | |
// Hello world! | |
// Goodnight moon! |
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
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("") |
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
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 |
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 array = ["π"] | |
array.push("π") | |
console.log(array) // Array [ "π", "π" ] |
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
setSearches([query].concat(searches)) // prepend to React State |
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
/** | |
* 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, |
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
/** | |
* 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 |