let message1 = 'hello world!';console.log('message1: ', message1)console.log('type of message1: ',typeof message1)console.log(message1.toUpperCase())let message2 = String('hello world!');console.log('message2: ', message2)console.log('type of message2: ',typeof message2)console.log(message2.toUpperCase())let message3 = new String('hello world!');console.log('message3: ', message3)console.log('type of message3: ',typeof message3)console.log(message3.toUpperCase())
02:51 Oops. Let's remove w from hello and here is our hello world.
03:00 Finally we will have message3 using the new keyword with string constructor and the same string hello world. So now you can see we have used all three approaches to create a string. Now that we have string ready, let's try to log if all of three result in the same string. So we do it for, message1 and try to log what's the value of message1. We do the same thing. Copy and paste for the second message and just change the value and same for message3. Now when we run this, we see that message one and two are hello world, but message three looks a little bit different. Well it is different because it's an object, but let's prove that we will make use of typeof operator which lets us know that type of value stored in a variable. So let's say typeof message, we will have a label with typeof message1.
03:55 We do the same thing for message2 just rename them. And the same for message3 and there it is. We see that message1 and two are of type string. But message3 is of type object. Let's also try to use a method on message1 say toUpperCase(), we call it a method. And we do the same thing with say, message2 just change the name and with message3. All right, so all of them converted HelloWorld to the upper case. And that is because all the methods and properties that are available on message3, which is a string object, are also available on string primitives. If we try to look at message one dot, the list of methods, it's the same methods that are available on object. Now you know, what's the difference between string primitives and string objects and how to get the type when you are declaring and initializing a string?