toString vs valueOf methods | String Object In JavaScript

preview_player
Показать описание
🎁 Join my channel to get access to perks:

🧡 Hello All JavaScript Lovers Outhere!

Today you're going to learn about the String Object In JavaScript.

This tutorial is a series of videos, in each video we will discuss a method (or more) of the String Object in JavaScript.

In today's video, you're going to learn about the toString, and valueOf methods.

The toString() method of a string object returns a string representing the specified string.

The valueOf() method returns the primitive value of a String object.

🔷 Syntax :
toString()

🔷 Syntax :
valueOf ()

toString :

valueOf:

This method is usually called internally by JavaScript and not explicitly in code.

🌍 Social Media Links.

💲 Suppport the Channel
Рекомендации по теме
Комментарии
Автор

CASE 1 - string primitive in a variable:
I would add that when JS internally transforms a string primitive to a String object via “wrapping”, it does so only for the few milliseconds needed to access the method we specify. The string primitive has no methods of its own, but the String object wrapper does. After the method executes, the wrapper is then shed and we revert back to an immutable string primitive. The String object wrapper is then garbage collected. This “wrapping”, i.e. the String object creation / destruction / garbage collection cycle, repeats every time we apply another method to the string primitive.

CASE2 - String object (via constructor function) in a variable
The string primitive is passed as an argument (i.e. a variable) to the constructor function. The String object is created and it persists as an object. We can now access methods at will, i.e the “wrapping” creation / destruction / garbage collection processes are N/A after the constructor creates the String object. Internally, the immutable string primitive also persists.

stephen
Автор

i just not got it, you are saying that apply these two properties are useless because javascript does it on its own? ohhhh okay actually thats my fault not the content i ve been looking you are working with objects, by the way good content keep it this way.

LucasSantos-njpv