0

I'm using vuex-module-decorators and I would like to know if I should set the default value of a data property to null or undefined. Example:

export default class ComponentName extends Vue {
 post: BlogPost | null = null
}

or

export default class ComponentName extends Vue {
 post: BlogPost | undefined = undefined
}

Is there a right answer?

mamonas
  • 25
  • 1
  • 6
  • Does this answer your question? [What is the difference between null and undefined in JavaScript?](https://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript) – Alejandro Aug 14 '20 at 03:48
  • nop, that's a vue question, not a javascript question. – mamonas Aug 14 '20 at 04:23
  • 1
    Data types are inherited from javascript, so that answer applies to your question. – Radu Diță Aug 14 '20 at 10:31
  • It doesn't :). Check the answer, there is context in `null` and `undefined` for state in Vue. – mamonas Aug 14 '20 at 16:00

1 Answers1

1

If state value cannot be determined, it MUST be initialized with null. Just like wheels: number | null = null.

From the docs.

Matthias
  • 3,729
  • 22
  • 37