I have been learning JavaScript and I am struggling to understand the coding style I see in the code I read. I am familiar with the "old" way of writing JavaScript but I haven't come across any resources that explain this new way of creating and calling JavaScript functions. Here is an example of the "new way":
// object
var dog = {
color: 'brown',
size: 'big'
};
//function to write dog size
(function(dog) {
return dog.size;
})(dog);
From the JavaScript documentation, I am familiar with the "old way" of doing things:
function prinSize(dog) {
return dog.size
}
console.log(prinSize(dog));
Can you please provide me with a link to the JavaScript documentation that explains why:
in JavaScript code, there are brackets at the start and end of a function
it is possible to write brackets with .(dog) after declaring a function, which allows you to actually call the function with the argument dog.