Question 1. What Is Knockoutjs ?
Question 2. Why Is Knockoutjs Useful ?
Knockout can dramatically reduce the amount of code needed to synchronize a data model and user interface controls. It is fast, cross browser compatible, and not reliant on any other libraries. It is lightweight (< 20kb after compression) and can be easily integrated with most web applications without any major architectural update.
Question 3. Describe A Knockout Viewmodel?
Question 4. How Do You Activate A Knockout Model ?
To activate a model, we call the key method ‘ko.applyBindings’, passing in the name of the model to bind to as a parameter. ‘ko.applyBindings(MyNewKOModel)’.
Question 5. Can You Have Multiple Knockout Models On One Page, And If So, How Would You Use Them?
Yes, Knockout can bind to multiple models at one time. The key to keeping the different models isolated is to put any mark-up in separate div containers, named with a unique ID, and to call the key ‘applyBindings’ method for each model, passing in the viewModel as the first parameter, and the matching div ID as the second parameter.
Question 6. What Is Two Way Data Binding?
Knockout uses the “data-*” tags to create a live dynamic link between a browser UI control, and a member or method inside a data ViewModel. If you have a data model with a field ‘FirstName’ and an edit box linked using the data-bind attribute to ‘FirstName’, then anytime the data model changes (for example programmatically), that change immediately shows in the edit box, and any time a user makes a change to the FirstName in the edit box, the underlying data in the field ‘FirstName’ is changed.
Question 7. What Is An Observable?
In knockout, declaring a member as observable means when its value changes any other object watching the member gets notified it has been changed. This simple concept allows the two-way data-binding to be implemented.
Question 8. What Is An Observable Array And Give An Example Of Where They Are Useful?
Simply, it is an array of observable objects. Observable arrays can be when handling object collections such as the individual items in a shopping cart for example.
Question 9. What Is A Computed Observable?
This is a special type of function that is dependant on one or more observables to work. For example, when the one or more observable value the computed is linked to changes, the computed observable gets called. The classic example is a computed called ‘Full Name’ which observes and combines ‘first name’ and ‘last name’ to make ‘Full name’.
Question 10. How Do You Search Or Sort An Observable Array?
You can search and sort using a ‘ko.Computed’ function. The computed function could implement an ‘arrayFilter’ call from the Knockout utils library to search, and a relevant compare (on string, number, date) for the sort. In all cases, the computed function filters out what it doesn’t want and returns data accordingly.
Question 11. How Do You Prepare A Knockout Object For Data Transfer ?
Question 12. What Is The Purpose Of The Mapping Plugin ?
When loading data into a viewModel, if it is complex with nested arrays, it can be troublesome to unwrap all members manually. The mapping plugin assists with this and allows you to tell Knockout how to handle complex data like structures with nested arrays by providing pattern functions.
Question 13. What Is A Binding, What Are The Binding Types, And What Are They Used For?
A binding is a html mark-up attribute that is added to an html element to create a link between the html control element and a knockout object. It takes the format ‘data-bind:
’. There are binding types to assist with objects like control text, visibility and CSS styles, and other types to assist with form fields such as value, submit, event, etc. Bindings might be used to display the title label of a page, the visibility of a checkbox, and control the data entry in form field.
Question 14. How Can You Control Flow With Bindings?
When you have an array of items in a Knockout viewModel, you can tell your mark-up to iterate through them using the data-bind ‘for-each’ for example.
Question 15. Give A Benefit Of Using Knockout Form Binding?
Normal functionality we might implement around form fields such as getting/setting the field value, hooking events, etc. can be carried out using ‘form data-bind’. A benefit of doing this is that we allow control of the form to be tied to the data model and its rules.
Question 16. How Do You Delete An Item From A Knockout Array?
Use the remove and removeAll methods, passing in the item you want to match for deletion.
Question 17. How Would You Flag An Item Deleted And Why Is This Useful ?
In cases where you want to manage an array of existing data for example browser-side, and inform the server of both additions, changes and deletions, you can flag an array item using the ‘destroy’ or ‘destroyAll’ method. This creates a dirty record that is flagged “_destroy” and can be easily identified server-side for handling in the data repository.
Question 18. How Do You Call A Knockout Method Using Data Bind Concept ?
Knockout allows us to use the data-bind concept to hook into user control object events such as ‘click’. To do this, we use a ‘data-bind’ with the method we want to call as the click parameter ‘data-bind=”click: callSomeMethod”’.
Question 19. What Is A Use Of Templates In Knockout And How Are They Coded ?
Question 20. Name Two Context Properties In Knockout And Explain Their Use?
When working with arrays, the $index property returns the index of the current context item in the array. When working with nested objects, the $parent property allows us to examine the parent of an object, for example a customer may have many orders, an order may have many line items. The order is the parent of the line item, the customer is the parent of the order.
Question 21. What Is The Features Of Knockout Js?
Dependency Tracking – Knockoutjs make dependency between View and ViewModel. Knockoutjs track any changes on dependent object when.
When dependent object in the dependency tracking, Knockoutjs automatically update the UI (DOM) when your data model is change.
Declarative Binding – In the declarative binding, your UI (DOM) is connected to your data model in a simply manner using data-bind control
Automatic UI Refresh –knockoutjs automatically refresh UI when ViewModel update. Any changes ViewModel data automatically refresh on view.
Template Binding – Templating is use for build sophisticated UI in easily. Knockoutjs populate the DOM element in nested and repeating manner with the help of foreach, if, with, and other control flow bindings and third party template engine.
Compact Size – Knockoutjs size is around 13kb after gzipping
Support all modern – Knockoutjs support almost every modern browsers (IE 6+, Firefox 2+, Chrome, Safari, others)
Easy to implement – No need to change existing architecture of project. Can easily implement existing architecture with the help of KO.
Question 22. What Is The Benefit Of Mvvm?
- Separation between UI and logic
- Reduce development Time
- Reusability of UI
Question 23. What Is Observable In Knockout Js?
Observable is a model property which is use to notify subscribers changes and it automatically detect dependencies. Observable property updates your UI automatically when the view model changes.
Question 24. What Is Different Way Of Using Templates In Knockoutjs?
Knockoutjs provide two ways to use templates.
Native Templating – Its way to build sophisticated UI using foreach, if, with, and other control flow bindings. Native Templating dependent on knockout itself.
String-based Templating –String-based templates use to work with third-party template engine like jQuery.tmpl or the Underscore template engine.
Question 25. How Many Types Of Data Binding Available In Knockout Js?
- Visible Binding
- Text Binding
- Value Binding
- CSS Binding
- style Binding
- Attr Binding
- Template Binding
HTML 5 Interview Questions
HTML 5 Tutorial
Adv Java Interview Questions
Adv Java Tutorial
MySQL Interview Questions
Angular JS Interview Questions
GNU Image Manipulation Program(GIMP) Interview Questions
HTML 5 Interview Questions
Java Abstraction Interview Questions
Adv Java Interview Questions
JqueryUI Interview Questions
jQuery Mobile Interview Questions
MySQL Interview Questions