console.log(functionOne());
console.log(functionTwo());
var functionOne = function() {
return “Hi! Hello I am functionOne”;
};
function functionTwo() {
return “Hi! Hello I am functionTwo”;
}
functionOne
should push to the top of whatever it is defined in and it should print out it's value. It will only exist in the scope it is defined in.functionTwo
should produce anundefined
error and will exist in the global scope most likelywindow
window.location.reload(true); // force a reload from the server
[1,2,3,4].forEach(num => console.log("hi " + num));
They are similar in behavior, they immediately invoke whatever they are used on. The difference between the two is the argument list.
Not sure what this question is about.
They usually present information like a count.
I had to research this one but there are several ways: https://www.w3.org/Style/Examples/007/center.en.html
use
ng-class
with an expression
you can't use the opacity property so you have to use rgba values.
Biggest difference is that using
ng-if
will either put something in or leave it out of the DOM.ng-{show,hide}
will leave it in the DOM and it will be watched and executed on by the digest cycle.
emit()
sends an event from the current scope up to the root scope.broadcast()
goes the other direction, it sends the event to the child scopes.
It's used mainly for anything that may be long running and you don't want to wait synchronously for it to return. Not sure what the second part is asking, but a promise returns a promise so you can easily compose it.
apply()
is on an island compared to watch()
and digest()
with how it is used. you shouldn't be calling digest()
directly whereas the others should be called directly.
any function or self executing function module can be considered a closure.
It just limits the usage of the directive to certain types of html items (attribute, element, class). Multiple attributes can be used.
(function(){
var a = b = 3;
})();
console.log("a defined? " + (typeof a !== 'undefined'));
console.log("b defined? " + (typeof b !== 'undefined'));
the first console statement will return
false
since the scope ofa
only exists in the function (closure) the second console statment will returntrue
since the scope ofb
will be global
console.log(add(2,3)); // Outputs 5 console.log(add(2)(3)); // Outputs 5
const add = function (num1, num2 = 0) {
if(arguments.length === 2) return num1 + num2;
return (anon_num) => num1 + anon_num;
}
reverseString(“sample”) should return “elpmas”
const reverseString = (str) => str.split("").reverse().join("");
Input- aacaabbbzzddss
Output - a4b3c1d2s2z2
const chrCount = function(input) {
let count = 0;
let output = [];
input.split("").sort().forEach((chr, index, arr) => {
if(arr[index] === arr[index + 1]) {
count++;
} else {
output.push(chr + ++count);
count = 0;
}
});
return output.join("");
}
angular.module('MyModule', [])
.controller('Controller', ['$scope', function($scope) {}])
.directive('countryCodes', function() {
return {
restrict: 'A',
template: `
<select name="country" id="country">
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
...
</select>
`
};
});
function MyModule($provide, $filterProvider) {
$filterProvider.register('r2d', function() {
return function(rupees) {
return rupees * 0.02;
};
});
}
Authenticate the user from the following restful API by passing username and password as query string.
https://mysite.com/api/login?username= ? && password = ?
this seems a bit involved, gonna skip for now.