Tuesday, April 28, 2015

knockout js interview questions and answers

knockout js interview questions and answers

http://www.code-sample.com/2014/01/knockout-js-interview-questions-and.html

1. What is Knockout JS?
Knockout is a pure JavaScript library and with the help of knockoutJS we can create rich and responsive applications. In knockoutJS, UI (DOM) is directly linked with data model.



If data source of the data model is getting update any time, at the same time the UI (DOM) sections will also get updated automatically.

KnockoutJs is a MVVM design 
pattern. The MVVM basically know as Model View ViewModel.

By the help of KO, we can implement all functionality more simply manner and works with any server or client-side technology.

Feature of KnockoutJs

  • Dependency Tracking
    • In the dependency tracking, Knockout js 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.
2. What is the main features of Knockout JS?

       The features of KnockoutJs

  • dependency tracking
  • declarative binding
  • template binding                                                                                          [<ul data-bind="template:{ name:'myViewItem',foreach: myItems }"></ul>]
3. How Knockout js different from MVC ? (Answers)

           ·   Knockout js is a MVVM pattern.
           ·   MVC is a design pattern.

           ·   Knockout js work like connected mode.
           ·   MVC work like disconnected mode.

           ·   Knockout js supported two types of binding
o   One-way binding
           ·   MVC supported only one-way binding.

           ·   In Knockout js, UI part automatically update when your data model update.
           ·   In MVC, not update UI automatically when your data model update. Need event to call data model and update it.

           ·   In MVC, model part directly bind with the view page.
           ·   In Knockout js, model part is not directly bind with the view page. Model directly bind with the view-model and view-model directly with the view page.

4. How Knockout js different from jQuery?
5. What is the KO and why we use, explain in details?
KO is a heart and soul of knockoutJS that provides interdependent way to link the ViewModel to Model and ViewModel to UI. 

Th KO doese not depend on the jQuery library, but we can use jQuery at the same time. Using KO you can handle client and server side application in simply manner.


6. What is observable in Knockout JS?
    Observable is a knockout js property that contain the view model and this property is bind with UI (View) in two way binding.


7. What is observable Arrays in Knockout JS?
      Observable array is a knockout js property that contain the item collection in the view model and this property is bind with UI (View) in two way binding. 


8. What is computed observable?
      Computed observable is a knockout js function which are depends on the other observable properties. Computed function are automatically update when any changes on these dependencies.

Exp.    

    //count total draft entries and display on submit button.

    self.countTotalDraftEntries = ko.computed(function () {
        var sum = 0;
        ko.utils.arrayForEach(TimeEntries(), function (key) {
            if (key.Status() === 'Draft') {
                sum += 1;
            }
        });
        return sum;
    });


9. What is dependency tracking in Knockout Js?
  • In the dependency tracking, KnockoutJS automatically update the UI (DOM) when your data model is change.

10. What is indexOf? (Answers)

11. What type of manipulating in the observable Array

      There are different type of obervableArray manipulations

    • pop()
    • push()
    • shift()
    • unshift()
    • reverse()
    • sort()
    • splice()
    • remove() 
    • removeAll()


12. What types of data binding are available in knockout JS?

      There are different type of data bindings



13. What is template binding?
 [<ul data-bind="template: { name: 'myViewItem', foreach: myItems }"></ul>]


14. How to creating custom bindings in knockout JS?


15. How to get row index in knockout Js ?
   We can get the row index using $.index()
Q1. KO performs following operations

  1. Automatic Refresh
  2. Two way Binding
  3. Templating
  4. All of the above

Q2. On which event bindings in KO fire notification

  1. Change event
  2. Update event
  3. On Any event
  4. None of the above

Q3. Value of computed observable is determined at
  1. Time of creation
  2. Time of update
  3. Time of DOM loading
  4. Depends on implementation

Q4. ko.toJSON is used for following purpose

  1. convert objects that include observables to a JSON string
  2. to convert string to object
  3. to consume JSON service
  4. to consume any service

Q5. How we can add reference of KO in project

  1. using local reference
  2. using CDN
  3. using Nuget package
  4. all of the above

Q6. On which value of ViewModel property visible binding will be set to block?

  1. Null
  2. Undefined
  3. Zero
  4. All of the above

Q7. ViewModel can be created as

  1. Object literal
  2. Function
  3. Both
  4. None of the above

Q8. Click binding can be bind to what kind of property in ViewModel

  1. Function
  2. Boolean
  3. Array
  4. All of the above

Q9. For what purpose we use foreach binding in KO

  1. To duplicates section of markup for each entry in array
  2. To duplicates section of markup for each entry in ViewModel
  3. To duplicates section of markup for each entry in Model
  4. None of the above

Q10. The Value binding should be used with
  1. <input> , <select> , <textarea>
  2. <span>, <div>
  3. <radiobutton> <table>
  4. All of the above combination


No comments:

Post a Comment