Knockout JS اسئلة واجوبة المقابلات
سؤال 1. What is Knockout JS?
Knockout JS is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.
Example:
var viewModel = { name: 'John', age: 25 }; ko.applyBindings(viewModel);
سؤال 2. Explain two-way data binding in Knockout JS.
Two-way data binding in Knockout JS ensures that when the UI changes, the underlying data model is automatically updated, and vice versa.
Example:
HTML: ; JavaScript: var viewModel = { name: ko.observable('John') };
سؤال 3. What is an observable in Knockout JS?
An observable in Knockout JS is an object that can notify subscribers about changes, allowing the automatic updating of UI elements.
Example:
var observableValue = ko.observable('Initial value'); observableValue.subscribe(function(newValue) { console.log('New value:', newValue); });
سؤال 4. How does the 'foreach' binding work in Knockout JS?
The 'foreach' binding is used to iterate over an array and generate content for each item in the array within the specified HTML element.
Example:
HTML:; JavaScript: var items = ko.observableArray(['Item 1', 'Item 2']); ko.applyBindings({ items: items });
سؤال 5. Explain the concept of computed observables.
Computed observables in Knockout JS are functions that automatically update whenever the underlying observables they depend on change.
Example:
var firstName = ko.observable('John'); var lastName = ko.observable('Doe'); var fullName = ko.computed(function() { return firstName() + ' ' + lastName(); });
الاكثر فائدة حسب تقييم المستخدمين: