May 2017
Intermediate to advanced
388 pages
7h 30m
English
In JavaScript, there are five primitive types: undefined, null, boolean, string, and number; everything else is an object. If we pass an object to a function (which itself is an object), then the object is passed by reference and not by value.
If the function modifies that object, it is something that we call an impure function; this is also known as a function with side effects.
Let's create a very basic sample to grasp the idea:
function getNewMessage(old_message){ old_message.message = 'new message'return old_message}var old_message = { message: 'old message'}var newMessage = getNewMessage(old_message)console.log(newMessage)console.log(old_message) // the old_message changed
In this sample, we created a function ...
Read now
Unlock full access