Skip to content

Instantly share code, notes, and snippets.

@itproto
Created June 26, 2024 09:17
Show Gist options
  • Save itproto/68975181ba0d7cba2b7dc8897c7d5bfd to your computer and use it in GitHub Desktop.
Save itproto/68975181ba0d7cba2b7dc8897c7d5bfd to your computer and use it in GitHub Desktop.
Typescrip Syntax refresher

any void

boolean number string

null undefined

bigint symbol

string[] /* or Array / [string, number] / tuple */

string | null | undefined /* union */

never /* unreachable */ unknown enum Color { Red, Green, Blue = 4 };

let c: Color = Color.Green

class Point { x: number y: number static instances = 0 constructor(x: number, y: number) { this.x = x this.y = y } }

@itproto
Copy link
Author

itproto commented Jun 26, 2024

function fizzBuzz(n: number): void {
for (let i = 1; i <= n; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}
}

// Example usage:
fizzBuzz(15);
// Expected output:
// 1
// 2
// Fizz
// 4
// Buzz
// Fizz
// 7
// 8
// Fizz
// Buzz
// 11
// Fizz
// 13
// 14
// FizzBuzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment