I've just started reading JavaScript: The Definitive Guide and I don't understand what the author means when he says:
"The most important thing about functions in JavaScript is that they are true values and that JavaScript programs can treat them like regular objects."
What does he mean that they are "true values"? And why does this mean that they can be treated like objects?
The TRUE Function[1] is categorized under Excel Logical functions. It will return the logical value of TRUE. The function is equivalent to using the Boolean value TRUE directly in a formula. In financial analysis, the TRUE function is often used with other logical functions such as IF, ERROR, etc.
You can also enter the value TRUE directly into cells and formulas without using this function. For example: =IF(A1=1,TRUE) If the condition is met, Excel returns TRUE in both examples. If the condition is not met, Excel returns FALSE in both examples.
The TRUE and FALSE functions There are TRUE and FALSE functions in Excel as well. For instance, if you type “=TRUE()” into a cell, it will return the value TRUE. If you type “=FALSE()” it will return FALSE.
The IF function checks whether a condition is met, and returns one value if true and another value if false.
It means JavaScript does not make a distinction between functions or strings, or numbers or booleans, as far as it is concerned they're all the same.
They're all objects.
Objects are key/value pairs in JS, just like
"neilmunro".length;
Will be 9.
function sayHi() { console.log("Hi"); }
sayHi.name;
Will print out "sayHi".
Functions can be passed to other functions:
function doSomething(name, func) {
console.log("Hi: " + name);
func();
}
doSomething("Neil", function() { console.log("You're a human!"); });
It's a bit mind bending, and there's a lot more to it than just that, but it's the basic idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With