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
/* | |
// 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 |
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
/* | |
// 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. |
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
/* | |
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 |
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
/* | |
var message = 'hello' | |
var guestList = ['Zelda', 'Dorothy', 'Tallulah', 1, true, { x: 1 }, ['a', 1, false]] | |
var zeldaDetails = { | |
first: 'Zelda', | |
'last': 'Fitzgerald', | |
occupation: 'Writer' | |
} |
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
interface Tree { | |
branches: number | |
species: string | |
} | |
interface Vehicle { | |
position: number | |
speed: number | |
} | |
interface Animal { | |
legs: 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
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] |
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
type Input = string[] | number[] | |
interface Tree { | |
branches: number | |
species: string | |
height: number | |
rings: number | |
} | |
interface WildTree extends Tree { |
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
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 |
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
interface Person { | |
name: string | |
age: number | |
email: string | |
phone: string | |
} | |
interface SpecialPerson extends Person { | |
reason: string | |
} | |
const tallulah: SpecialPerson = { |
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
interface Guest { | |
name: string | |
age: number | |
email: string | |
phone: string | |
address: string | |
} | |
type GuestKey = keyof Guest // 'name' | 'age' | 'email' | 'phone' | 'address' | |
const dorothy = { |