Jump to content

Recommended Posts

I've just started learning js by reading Learning JavaScript by Shelley Powers. It's okay I guess... I'm through 4 chapters.

Anyways, there's this explanation of declaring new instances of objects. My question is, what's that for?

Chapter 4.1:

 

var holdAnswer = new Boolean(true);

 

This is the only line of the example... so isn't holdAnswer already a new variable?

So why use 'new'? The book only says you can do it, but not why.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/103614-why-declare-new/
Share on other sites

But why do i need to use 'new' to create an object or set the type of variable?

What is the difference between

 

var first = array()

 

and

 

var first = new array()

 

You can call Array() as a predefined class of javascript.

 

var first = new Array();

 

It means you a creating a new instance of the class Array.

 

Link to comment
https://forums.phpfreaks.com/topic/103614-why-declare-new/#findComment-530882
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.