# Can't get the difference

**URL:** https://forum.kirupa.com/t/cant-get-the-difference/650053
**Category:** programming
**Created:** [December 17, 2021, 8:20am UTC](https://forum.kirupa.com/t/cant-get-the-difference/650053 "2021-12-17T08:20:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![banchego](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@banchego](https://forum.kirupa.com/u/banchego)
#### Post date: [December 17, 2021, 8:20am UTC](https://forum.kirupa.com/t/cant-get-the-difference/650053/1 "2021-12-17T08:20:18Z")

</div>

What’s the difference in these codes if they work same?

```auto
const name = "Nick";
const age = 21;
const print = function(){
    console.log(`Mr. ${name} is ${age} years old`);
};
const person = {name, age, print};
print();

```

and this one

```auto
const name = "Nick";
const age = 21;
const print = function(){
    console.log(`Mr. ${this.name} is ${this.age} years old`);
};
const person = {name, age, print};
person.print();

```

---

<div class="post-metadata">

### Author: ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)
#### Post date: [December 17, 2021, 10:49am UTC](https://forum.kirupa.com/t/cant-get-the-difference/650053/2 "2021-12-17T10:49:03Z")

</div>

The first one doesn’t require `const person` to work at all.

You are creating an object `person` that references the `const name / age` and the function `print()` now as `properties` and a `method` of `person`

So in effect you are creating a ‘person’ for no reason.

maybe this will help…

```auto
const name = "Nick";
const age = 21;
const print = function(){
    console.log(`Mr. ${name} is ${age} years old`);
};

let person = {
  who: name,
  howOld: age,
  painter: print,
  printer: function(){
    console.log(`${this.who} is ${this.howOld} today`)
  }
}

print();
person.painter()
person.printer()

```

`print()` is calling `const print`  
`person.painter()` is calling `const print`  
`person.printer()` is calling `person[printer]`

if you call `printer()` you will get an error `printer not defined` because `printer()` is only defined on the `person` object.

whereas `person.painter` is saying `person.painter = const print` find `const print` and `call` it
