Last active
August 1, 2018 20:47
-
-
Save kristyburge/2379d5ee5c8e6d511f26fbdd7cf858f2 to your computer and use it in GitHub Desktop.
Using the new keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = new String('Hello world'); | |
/******* | |
You could do the above, but it's best to avoid it (instead do like the variable str2 below) | |
(because JavaScript knows that anything inside single or double quotes has the type of String) | |
Same goes for other primitives. This is for example purposes only. | |
NOTE: To clarify -- the only time I ever use the new keyword in practice is when I use a function constructor and create my own object type. | |
*******/ | |
var str2 = 'Hello world'; | |
// both have the prototype of String and inherit all the String methods and properties |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment