I would like to understand a little more about punctuation in programming so that I can better understand the code. I would like to know what function the point fulfills and what name it has in programming, I would like to know this in order to learn more.
Example:
var variable = 'Hola mundo';
variable = variable.replace(/\s/g,'_');
console.log(variable);
To understand a little better what I mean. What is the purpose of the point that connects console with log() console.log()
or in another example likevariable.replace()
Usually the "point" you are referring to, in general programming, means that you want to access "something" that is at a lower level. To follow your example:
the same with
variable.replace()
variable is the object and replace is a method that includes this object.The same thing happens with class attributes:
I'll give you a somewhat longer example:
This is the case in the vast majority of object-oriented programming languages except for a few (PHP...) where other punctuations are used to access their internal attributes.
I hope I have clarified your doubts
In programming languages, several types of philosophies are handled, one of the other popular ones is object-oriented programming, in which classes and methods are handled.
The dot could be said to be a delimiter that allows access to the attributes of a class. In JavaScript we have the philosophy that everything is objects, it could be specified as a class that has attributes and methods. In the example you give, it specifies that the object
console
has a function calledlog
, this allows access to the function through the point, in this case it would be handled as followsIt is necessary to clarify that not all languages work in the same way, in php you can access the functions of a class by means of arrows
->
in the following way, having a Hello class that has a world function, it would be accessed in the following way formIn this particular case, the point is used to access a method of a class that is nothing more than the call of a function as a parameter in an object.
Therefore, in object-oriented programming, the dot is used (not only) to access the methods or properties of an object.
Example if the house object has a color property of red value and an alarm() method which is a function that triggers the alarm:
This may vary depending on the language you use, but in object-oriented languages there are usually similarities in these types of concepts.