Following are some declaration of String in JAVASCRIPT
var str = "Hello World"
var str1 = new String("Hello World")
str2 = "Hello World"
What is the difference between declarations mentioned above. Memory wise or if any.
Following are some declaration of String in JAVASCRIPT
var str = "Hello World"
var str1 = new String("Hello World")
str2 = "Hello World"
What is the difference between declarations mentioned above. Memory wise or if any.
I believe the top two are equivalent and the first is just syntactic sugar for the 2nd.
The 3rd assigns the str2
variable to the global window
scope. You can test this by going into the Chrome Dev tools and typing that line and inspecting it with the following line: window.str2
will print the value you just assigned.