What are computed observables in Knockout.js?
154
27-Jun-2024
Updated on 27-Jun-2024
Ashutosh Kumar Verma
27-Jun-2024Knockout.js Computed Observable
The objects calculated in Knockout.js are unique view objects that update themselves whenever any of the clients changes. It is used to get or calculate values based on other visible or explicit JavaScript attributes in your visualization. Here is a detailed explanation:
Definition
Computed observables (
ko.computed()
) in Knockout.js are functions that compute a value based on other observables or simple JavaScript properties. They are automatically updated every time a care is due based on changes.Example-
In this example,
fullName
is a numeric observable based onfirstName
andlastName
. Whenever firstName or lastName changes,fullName
automatically computed its value (this.firstName() + ' ' + this.lastName();
).Output-
Also, Read: Explain the role of observables and computed observables in Knockout.js?