However as the console
object is guaranteed to always exist on the global object, the globalThis
part can be omitted, which is what we've been doing in our code samples.
Back in part 3 we used String(...)
and Number(...)
to convert between strings and numbers - these are also globals and could also be accessed by globalThis.String(...)
. But once again there's no need as these are built-in to JavaScript.
There are a wide range of globals built-in to the JavaScript language that you can depend on anywhere you write JavaScript code. There are many more added by browsers, providing a wide range of sophisticated features ranging from networking to accessing peripheral devices like cameras. Other environments such as node.js also add different sets of features. Tools like Construct also provide their own set of features. These sets of features are collectively referred to as Application Programming Interfaces, or APIs. We've covered a very small number so far. Later on this guide will cover several more features that are built-in to JavaScript and so will work everywhere you can JavaScript, as well as a few browser APIs, and some of the APIs specific to Construct.
Conclusion
In this part we've covered:
- Creating an object
- Adding and removing object properties
- Using strings to refer to object properties
- Using
in
to check if a property exists
- Nesting objects
- The
null
value
- Optional chaining with
?.
- How objects are passed by reference, whereas numbers and strings are passed by value
- Using the global object via
globalThis
There's more to cover about objects, since they're such a fundamental aspect of JavaScript programming. In particular using function properties on objects has some additional unique features. The next part will cover that and some more details about objects in JavaScript.
Learn more
If you want to dig deeper, you can learn more about the features mentioned in this guide at the following MDN Web Docs links:
Part 8
When you're ready to continue, head on to the next part at Learn JavaScript in Construct part 8: Object methods!