What are computed observables in Knockout.js?
623
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,
fullNameis a numeric observable based onfirstNameandlastName. Whenever firstName or lastName changes,fullNameautomatically computed its value (this.firstName() + ' ' + this.lastName();).Output-
Also, Read: Explain the role of observables and computed observables in Knockout.js?