# This is valid code, but the console says there is an error

**URL:** <https://forum.freecodecamp.org/t/this-is-valid-code-but-the-console-says-there-is-an-error/523654>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [June 30, 2022, 4:12pm UTC](https://forum.freecodecamp.org/t/this-is-valid-code-but-the-console-says-there-is-an-error/523654 "2022-06-30T16:12:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ImWillStill](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/imwillstill/32/265142_2.png) [@ImWillStill](https://forum.freecodecamp.org/u/ImWillStill)\
**Post date:** [June 30, 2022, 4:12pm UTC](https://forum.freecodecamp.org/t/this-is-valid-code-but-the-console-says-there-is-an-error/523654/1 "2022-06-30T16:12:42Z")

</div>

**Tell us what’s happening:**  
this is valid code, but the console says there is an error.  
TypeError: this is undefined

```
  **Your code so far**

```

```js
function Dog() {
this.name = "jimmybabimmy";
this.color = "yellow";
this.numLegs = null;
}
console.log(Dog())

```

```
  **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0`

**Challenge:** Define a Constructor Function

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/define-a-constructor-function)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [June 30, 2022, 4:16pm UTC](https://forum.freecodecamp.org/t/this-is-valid-code-but-the-console-says-there-is-an-error/523654/2 "2022-06-30T16:16:07Z")

</div>

> [@ImWillStill](#):
>
> `console.log(Dog())`

Delete this line. The next lesson will show you how to correctly call a constructor.

---

<div class="post-metadata">

**Author:** ![ImWillStill](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/imwillstill/32/265142_2.png) [@ImWillStill](https://forum.freecodecamp.org/u/ImWillStill)\
**Post date:** [June 30, 2022, 4:21pm UTC](https://forum.freecodecamp.org/t/this-is-valid-code-but-the-console-says-there-is-an-error/523654/3 "2022-06-30T16:21:53Z")

</div>

ok, thank you. i thought i had to initalize it.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [December 30, 2022, 4:21am UTC](https://forum.freecodecamp.org/t/this-is-valid-code-but-the-console-says-there-is-an-error/523654/4 "2022-12-30T04:21:58Z")

</div>

Closed on December 30, 2022, 4:21am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
