0

I want to have a variable that has a "main" value but has new properties that can only be used with that variable

<script type="text/javascript">
    var myVar="random value";
    myVar.prop1="other value"; //How do I make it so that myVar can have that property, but other strings can't
</script>
John White
  • 109
  • 1
  • 1
  • 6
  • A primitive (string, number, boolean, null, undefined) cannot have properties. point. – Bergi Nov 04 '14 at 13:59
  • The opposite is true too, i.e. something with properties (an object) can't have a "main value", which you can assign without overriding all its properties (doing so would simply make it a primitive string). – Peter Herdenborg Nov 04 '14 at 14:01

0 Answers0