JavaScript

Angular JS

Angular JS Interview Q

Angular JS Interview Q1

Type Script

Angular JS 1 Vs 2

http://www.codeproject.com/Articles/618484/Latest-jQuery-interview-questions-and-answers

TYPE SCRIPT

event.stopPropagation() stops an event from bubbling up the event chain, whereas event.preventDefault() only precludes the browser’s default action on that event from occurring, but the event still propogates up the event chain.

For example, consider the following code snippet:

// in this example, 'foo' is a div containing button 'bar'  $("#foo").click(function() {    // mouse click on div 'foo' });  $("#bar").click(function(e) {    // mouse click on button 'bar'    e.stopPropagation(); }); 

Due to the call to stopPropagation() in the button’s click handler, the event never propogates to the div so its click handler never fires. It effectively stops parent elements from knowing about an event on their children.

In contrast, if you replaced the above call to stopPropagation() with a call to preventDefault(), only the browser’s default action would be precluded, but the div’s click handler would still fire.

$.ajax({   url: 'getTwitterFollowers.php',   type: 'GET',   data: 'twitterUsername=jquery4u',   success: function(data) {  //called when successful  $('#ajaxphp-results').html(data);   },   error: function(e) {  //called when there is an error  //console.log(e.message);   } });

$.ajax({  type: 'GET',  url: 'http://www.blogoola.com/data/destinations.json',  async: false,  jsonpCallback: 'jsonCallback',  contentType: "application/json",  dataType: 'jsonp',  success: function(data)  {   $('#jsonp-results').html(JSON.stringify(data));   console.log(json);  },  error: function(e)  {     alert(e.message);  } });

$('#load-results').load('http://www.sitepoint.com .header', function(data){  //example of callback  console.log(data); });

$.getJSON('destinations.json', function(data) {   $('#getJSON-results').html(JSON.stringify(data)); });

Load

This method allows to make ajax call to the page and allows to send using both Get and Post methods.

$("#result").html(ajax_load).load(loadUrl, function (response, status, xhr) {                     if (status == "error") {                         var msg = "Sorry but there was an error: ";                         $("#dvError").html(msg + xhr.status + " " + xhr.statusText);                     }                 });

getJson

This method allows to get json data by making ajax call to page. This method allows only to pass the parameter by get method posting parameter is not allowed. One more thing - this method treats the respose as Json.

                $.getJSON(jsonUrl, function (json) {                     var result = json.name;                     $("#dvJson").html(result);                 });

get

Allow to make ajax request with the get method. It handles the response of many formats including xml, html, text, script, json, and jonsp.

 $.get(getUrl, { Name: "Pranay" }, function (result) {                     $("#dvGet").html(result);                 }                 );

post

Allows to make ajax request with the post method. It handles the response of many formats including xml, html, text, script, json, and jonsp. post does same as get but just sends data using post method.

 $.post(postUrl, { Name: "Hanika" }, function (result) {                     $("#dvPost").html(result);                 }                 );

ajax

Allows to make the ajax call. This method provides more control than all other methods we have seen. You can figure out the difference by checking the list of parameters.

                $.ajax({                     type: "GET",   //GET or POST or PUT or DELETE verb                     url: ajaxUrl,   // Location of the service                     data: "",   //Data sent to server                     contentType: "",  // content type sent to server                     dataType: "json",  //Expected data format from server                     processdata: true,  //True or False                     success: function (json) {//On Successful service call                         var result = json.name;                         $("#dvAjax").html(result);                     },                     error: ServiceFailed // When Service call fails                 });

Important Features

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly. It works with plain old JavaScript objects

Knockout is a tool for binding your model to the view, and automatically updating the view when things change. Angular does this too, but it also does much more. In fact Angular is more like a framework for building a Single Page Application (SPA). 

The MVC pattern used by AngularJS, and the dependency injection system, and the ability to easily create mocked dependencies in tests. There are pros and cons to both frameworks.

With Knockout we can data bind like this:

// JavaScript

var vm = {

    firstName = ko.observable('John')

};

ko.applyBindings(vm);

<!-- HTML -->

<input data-bind="value:firstName"/>

With Angular we data-bind like this.

// JavaScript

// Inside of a personController

this.firstName = 'John';

And the Angular HTML markup using the new “Controller As” syntax which I prefer over $scope.firstName.

<!-- HTML -->

<div ng-controller="personController as vm">

    <input ng-model="vm.firstName"/>

</div>

On the surface, it makes a lot of sense to ask that question, but in reality you are trying to compare a screwdriver to a toolbox. What do I mean by that? Well, Knockout is simply a data binding framework & a every good one at that. But Angular is much much more than just data binding. Angular also offers routing/navigation support, the async module loading (AMD) pattern, services for working with network calls like REST services and the cookie store to name a few not to mention it's own data binding framework.

The question isn't so much as if you would use Angular vs. Knockout. The questions you should ask yourself should start with "do I need data binding or do I need a SPA presentation framework." If you aren't building a SPA, I offer that Angular is way too much for what you need... if all you need to do is tighten that doorknob, you just need a screwdriver, not the whole toolbox. But if you are making a new door to mount in a gap in the hall, you'll need your whole toolbox with not only screwdrivers, but drills, hammers, sanders, levels... all sorts of tools.

http://www.dotnet-stuff.com/tutorials/knockout-js/introduction-of-knockoutjs-it-s-not-jquery

(1) How to disable right click option body oncontextmenu="return false;" 

(2)How to use Ltrim In Javascirpt?

var strTemp = " Left padded string";

alert(strTemp);

strTemp = LTrim(strTemp);

alert(strTemp);

(3)How to get A ASCII Value of ANy character ?

alert(Asc("a"));

alert(Asc("B"));

(4)Get Back Character to ASCII

alert(Chr(80));

alert(Chr(82));

(5)Use of CBool funation in javascript

var StringOne = "No";

if(CBool(StringOne))

{

alert("StringOne evaluates to true");

}

else

{

alert("StringOne evaluates to false");

}

(6)How to Add to integer in JAVSCRIPT ?

var One = CInt("17");

var two = CInt("35");

alert(One + Two);

(7)Concat two string

var One = CStr(1267);

var Two = CStr(3456);

alert(One + Two);

(8)How to add long Value in Javscript ?

var One = CSng("1267.45");

var Two = CSng("3456.67");

alert(One + Two);

(9)Get format acording to exponnet

var tal = 34.5562

alert(FormatCurrency(tal));

alert(FormatCurrency(1000));

(10)Number in the Format of Percent ?

var TheNumber = .15

alert(FormatPercent(TheNumber));

(11)How to get date in specific format ?

var date = "23/07/1983";

alert(date);

date = FormatDate(date,"mmmm/dd/yyyy")

alert(date);

(12)how to get Date ClientSide

var Date = GetDate("dd/mmmm/yyyy");

alert(Date);

(13)How to get Specific String in specific String

var StringOne = "here u can do this due to error Gitesh said ";

if(InStr(StringOne,"gitesh") > -1)

{

alert("Gites found in string");

alert("Term appears at character " + InStr(StringOne,"Gitesh"));

}

(14)How to check value is null or not ?

var EmptyVariable;

if(IsNull(EmptyVariable))

{

alert("Null value detected");

}

(15)How to check numeric value ?

var myVariable = "www.Dotnetquestion.info";

if(IsNumeric(myVariable))

{

alert("Numeric Value detected");

}

(16)how to join Array ?

var var = "dot,net ,question ";

var arr = Var.split(",");

var strTemp = Join(arr," - ");

alert(strTemp);

(17)Convert String in to Lower case ?

var strTemp = LCase("DOTNETQUESTION");

alert(strTemp);

(18)How to get first three Character of string ?

var str = "Dot Net Question";

Leftstr = Left(str,3);

alert(Leftstr);

(19)How to get a length of string ?

var i = Len("www.Dotnetquestion.info");

alert(i);

(20)How to get a substring from string ?

var Temp = "dot net programmer in dotnetquestion.info";

Temp = Mid(Temp,3,3);

alert(Temp);

(21)How to Get string in Proper Case ?

var temp = "gitesh chawla";

temp = PCase(temp);

alert(temp);

(22)Replace a string with another ?

var str = "www.dotnetquestion.com";

str = Replace(str,"com", "info");

alert(str);

(23)How to get string from right of string ?

var strTemp = "Here is javascript in dotnetquestion site";

strTemp = Right(strTemp,4);

alert(strTemp);

(24)Math function

var root = 4;

root = Sqr(root);

alert(root);

(25)How to match two string ?

var str1 = "dot net question"

var str2 = "DOT NET QUESTION"

if(strComp(str1,str2,1))

{

alert("Strings Match");

}

(26)Use of Intellisense Title Case ?

var str1 = "all about the dot net question";

str1 = TitleCase(str1);

alert(str1);

(27)How to get Number of Element in array ?

var strTemp = "dot ,net,question";

var arrTemp = strTemp.split(",");

alert("Array contains " + UBound(arrTemp) + " elements");

(28)How to get string in Upper Case ?

var str = "dot net question";

str = UCase(str);

alert(str);