FAQ: Introduction to JavaScript - Properties

THANKS :slight_smile:

1 Like

Hello guys,

I hope there will be no need to create another thread about my topic. I mean difference between instance and object

Here is what i understand (fix me if i am wrong)

  1. Class - is a template, blueprint - description of possible .properties and .methods() of objects.
  2. Object is a specific element of the class based on class blueprint. Let say objects are all of those cars .red, .blue, .white with ability to driveforward(), drive backward() and so on based on blueprint (class)
  3. Instance - is…here my confusion starts. :frowning:

Here is why:

I mean there are many sourcies about the topic. One of them says: - there no any difference between object and instance, another says that instance is specific object. I mean any other cars is objects, but this specific is instance.
And codecademy article says, that instance is not real, it is virtual. Has reference on something located in memory.

So my question:

Could anyone explan what is difference between instance and object ? Would be so happy if this explanation would be as easy and clear as possible.

Sorry if this is too foggy.

1 Like

The object is the thing that can be modeled. It is the control over all instances of that object.

Granted, each instance is virtual so vaporizes at end of session; however, the control model is still hard coded. We usually define objects with classes, but the environment has built in classes that also define the range of, shall we say, primitive objects such as numbers, strings, booleans, arrays, lists, dictionaries, &c. This collection is extended by inclusion of libraries with definitions of still more object models (classes) that when included offer us even more to instantiate our virtual collection from.

Bottom line, we use objects to define instances, in that order.

1 Like

Why would console.log(“Teaching the world to code”.length); result in 30
But console.log(‘Teaching the world to code’.length); throw an error?

???

 > console.log("Teaching the world to code".length)
   26
<- undefined
 > console.log('Teaching the world to code'.length)
   26
<- undefined
 > console.log(`Teaching the world to code`.length)
   26
<- undefined

The above demonstrates the use of double quotes, single quotes, and back ticks all as valid syntax.

Below we can conclude that the following will give a syntax error. This is due to the custom quotes, which Unicode characters are not recognized by the interpreter.

“Teaching the world to code”
‘Teaching the world to code’

Now as to the error, is it a console error or a lesson checker error? The lesson checker may only recognize double quotes.

1 Like

The 30 is because exercise specifies the string as: 'Teaching the world how to code' as opposed to 'Teaching the world to code'

I used single quotes and it worked fine.

1 Like