Vue Js Programming Standards 1 — Questions and Answers
Question 1: Which data binding interpolation goes by the term "Mustache"?
- v-model
- {{}} (Correct answer)
- ()
- vfor
Correct answer: {{}}
In Vue.js, the double curly braces `{{ }}` are used for text interpolation, allowing you to bind data directly into the DOM. This syntax is commonly referred to as 'Mustache' syntax due to its visual resemblance to a mustache, and it's a fundamental way to display reactive data in your templates.
Question 2: How does Vue.js implement the for loop?
- v-for (Correct answer)
- &v-for
- vFor ()
- None of these
Correct answer: v-for
Vue.js provides the `v-for` directive to render a list of items based on an array or object. It allows you to iterate over data and dynamically create multiple elements or components in your template, making it a powerful tool for displaying collections of data.
Question 3: How do I set up a Vue.js instance?
- var text = new class ({//options}).
- var text = new text ({//options})
- var text = new Vue({// options }). (Correct answer)
- var text = new object ({//options}).
Correct answer: var text = new Vue({// options }).
To create a new Vue.js application or component instance, you use the `new Vue()` constructor. This constructor takes an options object where you define the instance's data, methods, computed properties, and other configurations, which then allows Vue to manage the reactive behavior of your application.
Question 4: Which event modifier is only applied to stop clicks on the element itself?
- @click.stop
- click@.self
- @click.self.prevent (Correct answer)
- @click.once
Correct answer: @click.self.prevent
The `@click.self` event modifier ensures that the event handler is only triggered when the event originates directly from the element it's attached to, and not from any of its child elements. This effectively 'stops' the event from being handled by the parent if a child was clicked. The `.prevent` modifier, when combined, then calls `event.preventDefault()` to stop the default action of the element itself when clicked directly.
Question 5: Which is employed when a component property or a number of characteristics are to be dynamically bound to an expression?
- v-bind (Correct answer)
- v-html
- v-once directive
- v-pre
Correct answer: v-bind
`v-bind` is a core Vue.js directive used to dynamically bind one or more attributes, or a component prop, to an expression. This allows data from the Vue instance to flow into the HTML attributes or component props, making them reactive to changes in the data. Its shorthand syntax is a colon (`:`).
Question 6: How does vue.js describe filters?
- =
- !
- ?
- | (Correct answer)
Correct answer: |
In Vue.js (particularly Vue 2), filters are denoted by the pipe symbol (`|`) within mustache interpolations or `v-bind` expressions. They are used to apply common text formatting to data, allowing you to transform the value before it is displayed. For example, `{{ message | capitalize }}` would apply a `capitalize` filter to the `message` data property.
Question 7: The non-mutating approaches are represented by which of the following?
- Concat()
- Slice()
- Filter()
- Reverse() (Correct answer)
Correct answer: Reverse()
The `Reverse()` method in JavaScript is a **mutating** array method, meaning it modifies the original array by reversing its elements in place. In contrast, `Concat()`, `Slice()`, and `Filter()` are all non-mutating methods that return new arrays without altering the original. Given that `Reverse()` is the only mutating method among the choices, it is likely that the question implicitly intended to ask for a mutating approach, despite the phrasing 'non-mutating approaches'.
Which data binding interpolation goes by the term "Mustache"?