This code snippet is testing whether the variable module
exists or not - probably to detect if the code is running on browser or in a Node.js environment.
The operator typeof
says what is the type of a variable. If it does not exist, the value of that expression is undefined
:
var a = 10;
var b = "teste";
var c = { foo:"bar" };
console.log(typeof a); // "number"
console.log(typeof b); // "string"
console.log(typeof c); // "object"
console.log(typeof d); // "undefined"
In this example, the code "object"==typeof module
checks the type of the variable module
and compares with "object"
. If it is true, it is because this variable exists and is an object, if it is false it is probably because it does not exist (although it may exist and have another type). In the quoted expression, a false result will cause the command to stop there (short circuit), while a true one will execute the code that is to the right of the &&
.
Tip: this code is not the easiest to read because it was minified. So, if you want to understand it, first of all it is better to go through some automatic reformatting tool.
– bfavaretto
THANK YOU!! I searched this tool all over the web and did not find, I am very grateful for your comment!!
– Gymo
Even after going through there the code is nothing readable. Compare with the ~25 lines of code of the original (lines 15-41).
– bfavaretto