Skip to content

Instantly share code, notes, and snippets.

@davidystephenson
Created September 20, 2025 16:39
Show Gist options
  • Save davidystephenson/d209a8b7c7f416fe77b073aa9a2096f8 to your computer and use it in GitHub Desktop.
Save davidystephenson/d209a8b7c7f416fe77b073aa9a2096f8 to your computer and use it in GitHub Desktop.
// Primitive
var message = 'hello'
var count = 42
var correct = true
// Container/Collection
// Entity (One thing, multiple attributes)
var person = {
name: 'Zelda Fitzgerald',
occupation: 'writer',
}
// console.log('person', person)
person.name = 'Zelda'
person.age = 29
delete person.occupation
// console.log('person 2', person)
// Dictionary (many things)
var websters = {
aardvark: 'An animal with four legs',
apple: 'A sweet fruit',
apple: 'A sweet and sour fruit', // This is not recommended
anteater: 'An animal with a long nose'
}
// console.log('websters', websters)
function getRandomAnimal() {
var random = Math.random()
if (random > 0.5) {
return 'aardvark'
} else {
return 'anteater'
}
}
var animal = getRandomAnimal()
delete websters[animal]
// console.log('websters 2', websters)
var countries = ['France', 'India'] // { '0': 'France, '1': 'India' }
// console.log(countries[1])
function greet() {
console.log('Hello, how are you doing today?')
}
// greet()
// greet()
// var greeting = greet()
// console.log('greeting', greeting)
// function add (a, b) {
// return a + b
// }
// var add = function (a, b) {
// return a + b
// }
// var total = add(9000, 5)
// console.log('total', total)
// console.log('typeof add', typeof add)
var calculator = {
history: [],
add: function (a, b) {
var complete = () => {
var result = a + b
this.history.push(result)
return result
}
var result = complete()
return result
},
}
// calculator.add(4, 1)
// console.log(calculator.history)
// var countries = ['France', 'India', 'Tanzania']
// for (country of countries) {
// console.log('country:', country)
// }
// countries.forEach((country) => {
// console.log('COUNTRY:', country.toUpperCase())
// })
// console.log('countries', countries)
// var name = 'Zelda'
// var yell = (message) => {
// message = message.toUpperCase()
// console.log('message', message)
// }
// yell(name)
// console.log('name', name)
// var x = 10
// function addTen (number) {
// x = 100
// return number + x
// }
// var result1 = addTen(90)
// console.log('result1', result1)
// var result2 = addTen(9000)
// console.log('result2', result2)
// console.log('x', x)
// const result = (function (number) {
// var message = 'I LOVE JAVASCRIPT'
// console.log(message)
// console.log('this is a number', number)
// return number * 2
// })(42)
// console.log('result', result)
// var message = 'JAVASCRIPT'
// console.log('hello', message)
var calculator = {
history: [],
add: function (a, b) {
const result = a + b
this.history.push(result)
return result
}
}
const result = calculator.add(5, 10)
console.log('result', result)
console.log('history', calculator.history)
var data = { history: [] }
// calculator.add.call(data, 5, 10)
// calculator.add.apply(data, [5, 10])
var bound = calculator.add.bind(data, 5, 10)
// var bound = function () {
// calculator.add(5, 10)
// }
bound()
bound()
console.log(data.history)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment