concept state in category javascript

This is an excerpt from Manning's book Testing JavaScript Applications.
Run this test and see what happens. You will notice that the tests pass but that Jest doesn’t exit. To detect what caused this, you can use Jest’s
detectOpenHandlesoption. When running Jest with this flag, it will tell you what prevented your tests from exiting.
We will cover replacing your in-memory database with an external one later in this chapter. For now, focus on understanding why and how to separate the different parts of your application.

This is an excerpt from Manning's book Functional Programming in JavaScript.
Functional programming falls under the umbrella of declarative programming paradigms: it’s a paradigm that expresses a set of operations without revealing how they’re implemented or how data flows through them. The more popular models used today, though, are imperative or procedural, and are supported in most structured and object-oriented languages like Java, C#, C++, and others. Imperative programming treats a computer program as merely a sequence of top-to-bottom statements that changes the state of the system in order to compute a result.
On the other hand, because FP is based on purity and referential transparency, by isolating the behavior from the state you can add more operations by defining and combining new functions that work on those types. Doing this, you end up with simple objects in charge of storing data, and versatile functions that can work on those objects as arguments, which can be composed to achieve specialized functionality. You haven’t learned about composition yet (it’s covered in chapter 4), but it’s important to highlight another fundamental difference between the paradigms. In essence, what inheritance does for OOP, composition does for FP in terms of applying new behavior to different data types.[1] To run this code, you’ll use the following dataset:
class Address { constructor(country, state, city, zip, street) { this._country = country; this._state = state; this._city = city; this._zip = zip; this._street = street; } get street() { return this._street; } get city() { return this._city; } get state() { return this._state; } get zip() { return this._zip; } get country() { return this._country; } }
The state of a program can be defined as a snapshot of the data stored in all of its objects at any moment in time. Sadly, JavaScript is one of the worst languages when it comes to securing an object’s state. A JavaScript object is highly dynamic, and you can modify, add, or delete its properties at any point in time. In listing 2.1, if you expect _address to be encapsulated (the use of the underscore is purely syntactic) within Person, you’re wrong. You have complete access to this property outside of the class to do whatever you please or even to delete it.
Figure 6.4. Falsely making assumptions about the global state of the system causes simple tests to fail. The left side shows that all tests executed perfectly, because each test correctly prepared its surrounding state before executing. But shuffling the tests (right) invalidates all assumptions about the state.
![]()