Last active
June 11, 2020 10:41
-
-
Save blefebvre/ee3e6f90390119529b89cea166236984 to your computer and use it in GitHub Desktop.
Types in JS
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
// Examples of types in JS | |
let count = 1; | |
console.log(typeof count); // number | |
count = "1"; | |
console.log(typeof count); // string | |
count = {count: 1}; | |
console.log(typeof count); // object | |
count = () => 1; | |
console.log(typeof count); // function | |
count = [1]; | |
console.log(typeof count); // object | |
// Type inferrence with TS. React examples | |
// Start at level 1 | |
const [level, setLevel] = useState(1); | |
// Overlay which shows "Game over" | |
const [showGameOver, setShowGameOver] = useState(false); | |
// The shapes, ordered by how they will appear. This is empty until "Go" is clicked | |
const [shapes, setShapes] = useState<Shape[]>([]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment