-
Objects
An object in programming is like a container that holds things. It can be used to store information like a box can store toys. For example, we could create an object called "cat" and it could have different pieces of information inside it like the cat's name, its color, or even how many lives it has left. Objects help us keep track of all the pieces of information we need for a program.
-
-
Map, Dictionary, Variable Objects
Javascript
Example of object in javascript.
var person = {
	name: 'John',
	age: 36
};

console.log(person['name']); // John
console.log(person['age']); // 36
void main() {
 var person = {
	 'name': 'John',
	 'age': 36
 };

 print(person['name']); // John
 print(person['age']); // 36
}
import std.stdio : writeln;
import std.string;
import std.conv;

void main()
{
	string[string] person = [
		"name": "John",
		"age": "36"
	];

	writeln(person["name"]); // John
	writeln(to!int(person["age"])); // 36
}

<?php
$person = (object)array(
	'name' => 'John',
	'age ' => 36
);

print($person['name']); // John
print($person['age']); // 36
Python
Example of object in python.
person = {
	'name': 'John',
	'age': 36
}

print(person['name']) # John
print(person['age']) # 36

package main

import "fmt"

func main() {
	var person = map[string]interface{}{
		"name": "John",
		"age": 36,
	}

	fmt.Println(person["name"]) // John
	fmt.Println(person["age"]) // 36
}

-
-
-
Class Objects
Javascript
Example of class object in javascript.
class Person {
	constructor(name, age) {
		this.name = name;
		this.age = age;
	}

	greet() {
		console.log('Hello my name is ' + this.name);
	}
}

var human = new Person('John', 36);

console.log(human.name); // John
console.log(human.age); // 36
human.greet(); // Hello my name is John
class Person {
 String name;
 int age;

 Person(this.name, this.age);

 void greet() {
	print('Hello my name is ' + this.name);
 }
}

void main() {
 var human = new Person('John', 36);

 print(human.name); // John
 print(human.age); // 36
 human.greet(); // Hello my name is John
}

import std.stdio : write, writeln;
import std.string;

class Person {
	string name;
	int age;

	this(string name, int age) {
		this.name = name;
		this.age = age;
	}

	void greet() {
		write("Hello my name is ", this.name);
	}
}

void main()
{
	Person human = new Person("John", 36);

	writeln(human.name); // John
	writeln(human.age); // 36
	human.greet(); // Hello my name is John
}

<?php
class Person {
	public $name, $age;

	function __construct($name, $age) {
		$this->name = $name;
		$this->age = $age;
	}

	public function greet() {
		print('Hello my name is ' . $this->name);
	}
}

$human = new Person('John', 36);

print($human->name); // John
print($human->age); // 36
$human->greet(); // Hello my name is John
class Person:
	def __init__(self, name, age):
		self.name = name
		self.age = age

	def greet(self):
		print('Hello my name is ' + self.name)


human = Person('John', 36)

print(human.name) # John
print(human.age) # 36
human.greet() # Hello my name is John

package main

import "fmt"

type Person struct {
	name string
	age int
}

func (p Person) greet() {
	fmt.Println("Hello my name is " + p.name)
}

func main() {
	var human = Person{"John", 36}

	fmt.Println(human.name) // John
	fmt.Println(human.age) // 36
	human.greet()		 // Hello my name is John
}

-
-