Skip to content

Instantly share code, notes, and snippets.

/*
// 1. Write a JavaScript expression to calculate the sum of two numbers, `num1` and `num2`.
var num1 = 10
var num2 = 11
var sum = num1 + num2
console.log(sum)
// 2. Write a program to calculate the area of a rectangle given its length and width.
var length = 5
var width = 10
/*
// 1. Declare a variable called `personName` and assign your name to it.
var personName = 'David Y. Stephenson'
console.log(personName)
// 2. Create a variable `age` and assign your age to it.
var age = 34
console.log(age)
// 3. Create a variable `isStudent` and assign it a boolean value.
/*
var x = 8 - 1
console.log('x', x)
var y = 2 + 6
console.log('y', y)
var equal = x === y
console.log('equal', equal)
var notEqual = x !== y
console.log('notEqual', notEqual)
var greater = x > y
/*
var message = 'hello'
var guestList = ['Zelda', 'Dorothy', 'Tallulah', 1, true, { x: 1 }, ['a', 1, false]]
var zeldaDetails = {
first: 'Zelda',
'last': 'Fitzgerald',
occupation: 'Writer'
}
interface Tree {
branches: number
species: string
}
interface Vehicle {
position: number
speed: number
}
interface Animal {
legs: number
type Input <T> = string | number | T
const input1: Input<boolean> = true
const input2: Input<string[]> = true
type Collection <T> = [T, T, T]
const stringCollection: Collection<string> = ['a', 'b', 'c']
const numberCollection: Collection<number> = ['a', 2, 3]
type Input = string[] | number[]
interface Tree {
branches: number
species: string
height: number
rings: number
}
interface WildTree extends Tree {
type Input <T> = string | number | T
const i: Input<boolean> = false
const x: Input<number[]> = [1, 2, 3]
interface Guest {
name: string
email: string
age: number
interface Person {
name: string
age: number
email: string
phone: string
}
interface SpecialPerson extends Person {
reason: string
}
const tallulah: SpecialPerson = {
interface Guest {
name: string
age: number
email: string
phone: string
address: string
}
type GuestKey = keyof Guest // 'name' | 'age' | 'email' | 'phone' | 'address'
const dorothy = {