![]() ![]() It’s the kind of parentheses used for mathematical grouping. The parentheses here aren’t a part of typeof. To put it clear: typeof is an operator, not a function. You may also come across another syntax: typeof(x). Technically, such behavior isn’t correct, but can be convenient in practice. That also comes from the early days of JavaScript. But typeof treats them differently, returning "function". We’ll study functions in the next chapters where we’ll also see that there’s no special “function” type in JavaScript. The result of typeof alert is "function", because alert is a function.It is a special value with a separate type of its own. That’s an officially recognized error in typeof, coming from very early days of JavaScript and kept for compatibility. The result of typeof null is "object".Here, it serves just as an example of an object. Math is a built-in object that provides mathematical operations.The last three lines may need additional explanation: It’s useful when we want to process values of different types differently or just want to do a quick check.Ī call to typeof x returns a string with the type name: The typeof operator returns the type of the operand. We have to mention it here for the sake of completeness, but also postpone the details till we know objects. The symbol type is used to create unique identifiers for objects. We’ll deal with them later in the chapter Objects, after we learn more about primitives. ![]() In contrast, objects are used to store collections of data and more complex entities.īeing that important, objects deserve a special treatment. ![]() Objects and SymbolsĪll other types are called “primitive” because their values can contain only a single thing (be it a string or a number or whatever). Normally, one uses null to assign an “empty” or “unknown” value to a variable, while undefined is reserved as a default initial value for unassigned things. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |