0

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.

5

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.