Web Designing and Publishing

Javscript and Angular Js Question & Answer



Question : 1

What is JavaScript? 



Answer :

JavaScript is very powerful client side scripting language. It was developed by Brendan Eich in 1995.It is mainly used for enhancing the interaction of a user with a webpage. More interactive webpage can be designed using JavaScript. JavaScript is an object-oriented computer programming language commonly used to Create interactive effects within web browsers. It is first used by the Netscape browser, that Provides access to the HTML Document Object Model (DOM), provides access to the Browser Object Model (BOM).It allows pages to respond to events, display special effects, accept Variable text, validate data, make cookies, detect user’s browser.



Question : 2

What are the features of JavaScript? 



Answer :

Following are the features of JavaScript:

a. It is a lightweight, interpreted programming language.

b. It is designed for creating network-centric applications.

c. It is complementary to and integrated with Java.

d. It is an open and cross-platform scripting language. 



Question : 3

What is an operator and what are its types in JavaScript?



Answer :

Operators are used for comparing values, perform arithmetic operations, etc. For example, if we take a simple expression, 4+5 is equal to 9. Here 4 and 5 called operands and ‘+’ is called the operator. JavaScript consists of different types of operators that are used to Perform different operations.

Types of JavaScript Operators There are different types of operators in JavaScript that are used for performing different Operations. Some of the JavaScript Operators include:

a. Arithmetic Operators

b. Comparison Operators

c. Bitwise Operators

d. Logical Operators

e. Increment/Decrement Operator

f. Bitwise Operator

g. Assignment Operators

h. Conditional Operator



Question : 4

What is Angular JS expressions? Explain with example



Answer :

AngularJS expressions are those that are written inside double braces {{expression}}.AngularJS evaluates the specified expression and binds the result data to HTML. AngularJS expressions can also be written inside a directive: ng-bind="expression".

AngularJS expression can contain literals, operators and variables. AngularJS displays the data exactly at the place where the expression is placed.

For example, an expression {{6/2}} will produce the result 3 and will be bound to HTML.

 <html >
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
</head>
<body >
<h2> AngularJS Expression Example</h2>
 <div ng-app="">
<p> Addition: 6 + 2 = {{6 + 2}} </p> <br />
<p> Subtraction: 6 - 2 = {{6 - 2}} </p><br />
<p> Multiplication: 6 * 2 = {{6 * 2}} </p><br />
<p> Division: 6 / 2 = {{6 / 2}}</p>
 </div> 
</body>
</html>


Question : 5

What are Directives in Angular Js? Explain important directives.



Answer :

AngularJS directives are used to extend HTML. Directives are markers on HTML DOM element that tell AngularJS to attach a specified behavior to that HTML element.

Directives in AngularJS are special attributes starting with ng- prefix where ng stands for Angular. AngularJS includes various built-in directives, you may also create your own directive in AngularJS. Some built-in directives are listed here.

ng-app 

The ng-app directive defines the root element of an AngularJS application and starts an AngularJS Application.The ng-app directive will auto-bootstrap (automatically initialize) the application when a web page is loaded. It is also used to load various AngularJS modules in AngularJS Application.

ng-init 

ng-init directive initializes an AngularJS Application data. It is used to declare and assign values to the variables for an AngularJS application. 

ng-repeat

The ng-repeat directive repeats HTML elements for each item in a collection. Or simply say that it is used to loop through items in collection element and it will act as for loop.

ng-model 

The ng-model directive is used for two-way data binding in AngularJS. It is used to get value of input controls like textbox, label, etc and use these values in web pages.

ng-bind 

The ng-bind directive binds the model property declared via ng-model directive or the result of an expression to the HTML element. It also updates an element if the value of an expression changes. 




Question : 6

What is form validation in JavaScript? How client side validation is different from server level validation. 



Answer :

Whenever we are working with Forms on webpages to submit some data, the Form validations are usually occurring at the server end, i.e. as the user entered all the necessary data and press the Submit button, all the filled data are submitted to server and subsequently validated. If the data entered by the user is incorrect or simply missing, the server sends all the data back to the client and requests for resubmitting of data through form with correct information. This is really a lengthy process which used to put a lot of burden on the server.

Using JavaScript, there are ways to validate most of the form's data on the user system itself before sending it to the web server. This is called Form validation and generally performs two functions:

Basic Form Validation – In this, initially form must be checked to make sure all the mandatory fields are filled in. This is simple and requires a loop through each field in the form to check for data. For Example, Name, Mobile no. and email is mandatory. 

Data Format Validation – In this type of validation, the data entered can be checked for correct format and values (may be some value ranges). It is required that the JS code written must include appropriate logic to test correctness of data. For example, mobile no must be of 10 digits, email must be in correct format or PinCode shall be of 6 digits not starting with zero or Marks obtained shall be between 0 and 100. 



Question : 7

What are events? Where they are used. 



Answer :

When the user manipulates a page events may be occurred. Events are fired inside the browser window, and tend to be attached to a specific item that resides in it which may be a single element, set of elements, the HTML document loaded in the current tab, or the entire browser window. JavaScript's interaction with HTML is handled through events. Events are occurred whenever a page is loaded (page load event), the user clicks a button (button click event) or events are occurred on pressing any key, closing a window, resizing a window, etc. Some more types of events may occur on:

  • hovering the cursor over a certain element.
  • web page finishing loading.
  • A form being submitted.
  • A video being played, or paused, or finishing play.
  • An error occurring. 

The occurrence of these events may be used by the Programmers and to execute responses coded in JavaScript like cause buttons to close windows, messages to be displayed to users, data to be validated, or any other type of response.

Events are a part of the DOM (Document Object Model) Level 3 and every HTML element contains a set of events which may trigger a block of JavaScript Code written for that specific purpose, i.e. JavaScript can "react" on these events and allows executing the code when events are detected.

The most common Events are

onchange - An HTML element has been changed

onclick - The user clicks an HTML element (button, image etc)

onmouseover - The user moves the mouse over an HTML element

onmouseout - The user moves the mouse away from an HTML element

onkeydown - The user pushes a keyboard key

onload - The browser has finished loading the page  



Question : 8

What are AngularJS modules?



Answer :

AngularJS supports modular approach of programming. AngularJS modules are used to divide or separate the logic such as controllers, services, application etc. and keep the code clean. AngularJS module helps to link many components, so it is just a group of related components.

Generally in most of the applications we have a single entry point (main method) that instantiate and club together different parts of the application. In angularjs applications we don’t have that main method instead we have modules that specify how our application will be structured and bootstrapped.

Modules are defined in separate .js files and name them as per the module.js file, if these are kept in different file. Controllers always belong to a module.

Let us have two modules for an application, and we create them as

Application Module − used to initialize an application with controller(s). Application module is created by using the AngularJS function angular module  

Controller Module − used to define the controller. These refer to the controller with the ng-controller directive. 



Question : 9

What is JavaScript?



Answer :

JavaScript is an object-oriented computer programming language commonly used to create interactive effects within web browsers. It is first used by the Netscape browser, that provides access to the HTML Document Object Model (Dom), provides access to the Browser Object Model (BOM). It allows pages to respond to events, display special effects, accept variable text, validate data, make cookies, detect user's browser.



Question : 10

Explain what is pop() method in JavaScript?



Answer :

The pop() method is similar as the shift() method but the difference is that the Shift method works at the start of the array. Also the pop() method take the last element off of the given array and returns it. The array on which is called is then altered.

For example, var cloths= ["Shift", "Pant", "TShirt"];
cloths.pop();



Question : 11

What are the features of JavaScript?



Answer :

Following are the features of JavaScript:

a.  It is a lightweight, interpreted programming language.
b.  It is designed for creating network-centric applications.
c.  It is complementary to and integrated with Java.
d.  It is an open and cross-platform scripting language.



Question : 12

How can you create an Array in JavaScript?



Answer :

You can define arrays using the array literal as follows:
var x=[];
var y = [1, 2, 3, 4, 5];



Question : 13

What is an operator and what are its types?



Answer :

Operators are used for comparing values, perform arithmetic operations, etc. For example, if we take a simple expression, 4 + 5 is equal to 9. Here 4 and 5 are called operands and '+' is called the operator. JavaScript consists of different types of operators that are used to perform different operations.

Types of JavaScript Operators

There are different types of operators in JavaScript that are used for performing different operations. some of the JavaScript Operators include:

a.  Arithmetic Operators
b.  Comparison Operators
c.  Bitwise Operators
d.  Logical Operators
e.  Assignment Operators



Question : 14

What are events in JavaScript and its Types?



Answer :

JavaScript has events that provide a dynamic interface to a webpage. These events are connected to elements in the Document Object Model(DOM).

Also, these events by default use the bubbling propagation i.e., upwards in the DOM from children to parent. We can bind events either as inline or in an external script. With the help of JavaScript, you can detect when certain events happen, and cause things to accur in response to those events.

Types of Events in JavaScript

There are different types of events in JavaScript that are used to react to events. Some of the famous or most commonly used events such as:

a.  Onclick
b.  Onkeyup
c.  Onmouseover
d.  Onload
e.  Onfocus 



Question : 15

Explain what are directives? Mention some of the most commonly used directives in AngularJS application?



Answer :

A directive is something that introduce new syntax, they are like markers on DOM elements which attaches a special behavior to it. In any AngularJS application, directives are the most important components.

Some of the commonly used directives are ng-modal, ng- App, ng-bind, ng-repeat, ng-show etc.



Question : 16

What are the advantages of using Angular JS?



Answer :

a.  Angular JS has several advantages in web development.
b.  Angular JS supports MYC pattern.
c.  Can do two ways data binding using Angular JS.
d.  It has per-defined from validation.
e.  It supports both client sever communication.
f.  It supports animations.                                                                                                                                               ns



Question : 17

What do you understand by Angular JS?



Answer :

Angular JS is a JavaScript framework that is used for making rich and extensible web application. It runs on plain JavaScript and HTML; hence you don't need any other dependencies to make it work. Angular JS is perfect for Single Page Applications (SPA). It is basically used for binding JavaScript objects with HTML UI elements.



Question : 18

Distinguish between Angular JS and JavaScript expressions.



Answer :

There are several differences between Angular JS and JavaScript expressions:

a.  We can write Angular JS expressions in HTML, but we cannot write JavaScript expressions in HTML
b.  We cannot use conditional iterations, loops, and exceptions in Angular JS, but we can use all of these conditional properties in JavaScript expression.
c.  Filters are supported in Angular JS whereas filters are not supported in JavaScript.



Question : 19

What are the Angular Modules?



Answer :

The Angular modules collectivity define an angular application where we can write the angular code. It contains the different parts of an angular application. A module id created by angular module function in angular.



Question : 20

Explain the ng-model directive in Angular JS.



Answer :

This can be a leap hop with the custom HTML input from control (like input, textarea and select) to the application data. It provides from validation behavior with a two-way binding.
<input ng-bind="expression"/>



Question : 21

 What is a controller in Angular JS?



Answer :

A controller is a JavaScript function which is bound to the specified scope. Angular instantiates the new controller injects the new scope as a dependency. It can be used to set up the initial state of the scope object and to add behavior to the object. It cannot be to share code or state across controllers, but instead of that Angular service can be used.

Example,
<Any ng-Controller=" expression">
</Any>
<div ng-app="mainApp" ng-controller="SimpleController">
</div>



Question : 22

What is ng-App directive in Angular JS?



Answer :

It is used to define the Angular JS Application. It appoints the element of an Angular JS application and it is kept near the <body> or <html> tag.

We can define any number of ng-app directives inside the HTML document, but only one AngularJS application can be bootstrapped automatically (auto-bootstrapped) and the other applications need to be bootstrapped manually.

Example:
<div ng-app="">
<p>my first expression: { { 157 + 122 } } </p>
</div>



CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad Sarkari Exam Quiz