Questions


1) What is ECMAScript ?
This is the official name given to the language standard that Netscape originally submitted to ECMA for standardization.
Despite the official name this language is more commonly referred to as JavaScript.


2) Is JavaScript a Strongly Typed programming language ?
No. Type conversions can be implicit. This has nothing to do with Strict Mode.
JavaScript is dynamically typed. Data types are detected at run-time not during compilation.
You can reuse and reassign variables to lots of different types.

var str1 = '100';  
str1 = 20 * str1;
console.log( typeof(str1) ); // 'number'

3) Are semicolons required at the end of statements ?
No. They are not required although you should definitely include them.
If you do not include them you will be relying on a process called Automatic Semicolon Insertion (ASI).
This process will try to insert the semicolons for you automatically.
There are a number of cases when the ASI will insert one in the wrong place.

a = b + c 
(d + e).print()

This translates to "a = b + c(d + e).print" which is different.

return 
{
   var1 = 'Mon'
}

This translates to "return; { var1 = 'Mon' }" which is different.


4) What is Strict Mode ?
This is an option that can be used to force you to explicitly declare a variable before it can be used.
This allows you to place an entire file/script or just an individual function in a "strict" operating context.
Modules are automatically placed in strict mode, there is no need to add this statement.

'use strict'
function myfun() {
'use strict'
};

5) What is displayed in the Console ?

( function() { 
   var a = b = 3;
}) ();
console.log( typeof(a) ); // false with strict mode
console.log( typeof(b) ); // true with strict mode

This expression is shorthand for "b = 3, var a = b;"
Without the strict mode, we get false, true
In strict mode, we get runtime error b is not defined


6) Can you give some examples of the different types of actions that are prevented when using strict mode ?
*) The strings 'eval' and 'arguments' cannot be used as variable names.
*) Writing to a read-only property is not allowed.
*) The with statement is not allowed


7) What are 'undeclared' and 'undefined' variables ?
Undeclared variables - are those that do not exist and have not be declared. Reading the value from an undeclared variable will generate a runtime error.
Undefined variables - are those that have been declared but have not been given a value. Reading the value from an undefined variable will give you undefined.
If you declare a variable and do not assign a value to it, its value will be undefined.

var myUndefined; 
console.log( myUndefined ); //
console.log( myUndeclared ); // runtime error ?

8) Can you describe the difference between 'undefined' and 'null' ?
undefined - a variable that has not been given a value. It has not been initialised
null - a variable that has been explicitly set to have no value

var myNull; 
myNull = Null;
console.log( myNull );

If you compare undefined and null using the following line, they will be equal

if (null == undefined)            // return true 
if (null === undefined) // return true

null is also considered an object.

let var1 = null; 
console.log( typeof var1 === 'object' ) // true
let var2 = [];
console.log( toString.call(var2) === '[object Array]' ); // true
console.log( var2.constructor === Object );

9) Can you describe the different variable scopes ?
There are three scopes, global, function and block.
global scope - can be accessed from anywhere in the program
function scope - can be accessed only from within the function where it is declared
block scope - can be accessed only from within the block


10) How do you declare a variable ?
If you do not use the var keyword then it will be given global scope.
You can use the 'var' keyword to give your variable function scope.

global1 = 5;                     // variables are case sensitive 
var global2 = 10;
function Func1() {
   global3 = 10 * 2;
   var function1 = 10 * 2; // has function scope
};

11) What is the difference between 'var', 'let' and 'const'?
A variable declared with var outside a function has global scope.
A variable declared with var inside a function has function scope. This will take precedence over the same variable declared outside the function.
The scope of var can be global or function (not block).
The scope of let can be global, function or block.
The scope of const can be global, function or block and cannot be reused or reassigned later.
A variable declared with let at the global scope will not be added to the global window object.

var a = 'Tuesday';  
function MyFunc() {
   var a = 'Wednesday';
   console.log( a ); // ?
}
console.log( a ); // ?

12) Can you describe Variable Hoisting ?
Yes. JavaScript will automatically move all variable declarations to the top of the corresponding scope.
The initialisation will not been hoisted, only the declaration.

var a = 'Monday'  
function MyFunc() {
   if (a === undefined) {
      var a = 'Tuesday'
   }
   console.log(a);
};
MyFunc();

A new variable with function scope is declared inside the MyFunc function that has the same name as the variable at the global scope.
JavaScript always hoists variable declarations to the top of their scope.


13) What is the 'typeof' operator ?
This is a unary operator that takes a single operand and returns a 'string' description of the data type.

console.log typeof ( 'Hello World' );  // 'string'  
console.log typeof ( 19.5 ); // 'number'
console.log typeof ( true ); // 'boolean'

var myFunction = function(x, y) {
    return x + y;
};
console.log typeof ( myFunction ) // 'function'

14) Can you give some examples of Value data types ?
Also known as primitive data types.

number          // integer and floating point 
string
boolean
Symbol // added in ES 2015
null // represents an empty
undefined

15) Can you give some examples of Reference data types ?

Function 
Array
Object
Object - number
Object - string
Object - boolean

16) How can you check if a variable has a value ?
You can use the if keyword to check if a variable has a value.

if (myVar){ 
   // 0, NaN, "", null, undefined
}
else {
  // everything else
}

17) Can you describe the 'number' data type ?
Double-precision, 64 bit binary format, IEEE 754 value.
They are all represented as floating point values.
The fraction is 52 bits, the exponent is 11 bits, and the sign is 1 bit.
The smallest value is 5 E -324
The largest value is 1.7976931348623157 E 308

console.log( 3 + 2 + '6' );     // 56  
var a = Number.MIN_VALUE;
var b = Number.MAX_VALUE;

18) Can you explain the difference between the global Number() function and the Number constructor ?
The Number() function can be used with primitive/literal values or with objects.
When used with literal values this function can be used to convert literal values to a 'number' data type.
If the literal value cannot be converted to a number, NaN is returned.

let num1 = 10; 
let num2 = Number(10);
console.log( typeof( num1) ); // 'number
console.log( typeof( num2) ); // 'number
console.log( typeof( Number('111 222') ); // 'NaN ?

When used with the 'new' keyword this function can be used as a constructor to create a Number object.

let num3 = new Number(10); 
console.log( typeof( num3) ); // 'object

19) Can you list some Number properties ?
The Number data type also supports these special values.

NaN - not a number indicator (added in ES 2015) 
POSITIVE_INFINITY - when a number exceeds 1.7976931348623157 E 308
NEGATIVE_INFINITY - when a number exceeds -1.7976931348623157 E 308
MIN_VALUE -
MAX_VALUE -

20) Can you describe the 'NaN Property' ?

console.log( typeof (Number.NaN) );         // 'number  
console.log( Number.NaN === Number.NaN ); // 'false

21) Can you list some Number methods ?

toString - 
toExponential -
toFixed -
toPrecision -
valueOf - return the value from an expression

22) When would you use the global isNan() function ?
This function returns true if the argument is not a number otherwise it returns false.
This function converts the argument to a number and then tests it.

isNan(123)  // false 
isNan('text') // true
isNan(undefined) // true
isNan(0/0) // true

23) Can you convert a 'number' data type to a 'string' data type ?
Yes. There are several ways this can be done.

let num1 = 10; 
let string;
string1 = num1.toString(); // explicit
string1 = String(num1);
string1 = `${num1}`; // template strings
string1 = '' + num1; // concatenate empty string

24) Can you convert a 'number' data type to a 'boolean' data type ?



25) What is 0.1 + 0.2 ?
This is not 0.3 but is actually 0.30000000000000004
When performing integer calculation the results are precise but this is not the case when working with fractions.
It is good practice to always truncate fractions to a fixed number of decimal places.


26) What is the parseInt() function used for ?
This function is used to convert numbers between different bases.
Can parse a string and return an integer.

parseInt('4F', 16);  

27) What is the parseFloat() function used for ?
Can parse a string and return a floating point number.


28) Can you list the arithmetic operators
Addition (+)
Subtraction (-)
Division (/) -
Remainder (%) - modulo operation
Multiplication (*) -
Exponentiation (**) -
Increment (++) -
Decrement (--) -
Unary negation (-) -
Unary plus (+) -


29) Can you describe the 'string' data type ?
A string is a collection of characters.
It can be enclosed in single or double quotes.
You can use the plus sign to represent string concatenation
Some other common escape sequences are \t to embed a tab and \n to embed a new line.
You can also use \uHHHH where HHHH is a 4-digit hexadecimal code to embed a unicode string.
Special characters are single quote, double quote, apostrophe and ampersand.

'The quick brown fox jumps over the lazy dog'
'The doctor said "Today is your lucky day!" '
'The doctor said "I\'m pleased to announce that it\'s a girl!" '

30) Can you explain the difference between the global String() function and the String constructor ?
The String() function can be used with primitive/literal values or with objects.
When used with literal values this function can be used to convert literal values to a 'string' data type.
When used with the 'new' keyword this function can be used as a constructor to create a String object.

let str1 = 'text';                      // typeof = string  
let str2 = String('text'); // typeof = string
let str3 = new String('text'); // typeof = object

31) Can you convert a 'string' data type to a 'number' data type ?
Yes. There are several ways this can be done.

let str1 = 'text';  
let num1;
num1 = Number(str1); // explicit
num2 = 0 + str1; // implicit

32) Can you convert a 'string' data type to a 'boolean' data type ?



33) Can you explain why you can access properties off a string value data type ?
JavaScript will automatically convert value data types (number, string, boolean) to their object equivalent data types temporarily if it detects a property has been appended to a value data type.

var myString1 = 'some'  
console.log( typeof (myString1) ); // string
var length = myString1.length;
console.log( length );
console.log( typeof (myString1) ); // string

34) Can you describe the global eval() function ?
This function evaluates a string expression.

let a = 10; 
let b = 20;
let c = eval('a * b');

35) What are Escape Characters ?
These can be used when working with special characters like single quote, double quote, apostrophe and ampersand

console.log("some \" text");    // 'some " text' 

36) Can you describe the 'boolean' data type ?
This can contain the values true or false.

equals (==) 
not equals (!=)
null == undefined // true
false == 0; // true
'' == 0; // true
123' == 123 // true
boolean + number = addition

37) Can you explain the difference between the Boolean() function and the Boolean constructor ?
The Boolean() function can be used with primitive/literal values or with objects.
When used with literal values this function can be used to convert literal values to a 'boolean' data type.
When used with the 'new' keyword this function can be used as a constructor to create a Boolean object.

let bool1 = Boolean(false);               // typeof = boolean 
let bool2 = new Boolean(false); // typeof = object

38) Can you convert a 'boolean' data type to a 'string' data type ?

let bool1 = false; 
let str1;
str1 = false.toString();
str1 = String('false');

39) Can you convert a 'boolean' data type to a 'number' data type ?



40) Can you describe the logical operators ?

&& - and 
|| - or
! - not

JavaScript uses short-circuit evaluation


41) Can you describe the 'Symbol' data type ?
Added in ES 2015.
A symbol represents a unique identifier.
Using symbols guarantees uniqueness. The description is just a label.
Symbol conversion has to be explicit.

let id1 = Symbol("id"); 
let id2 = Symbol("id");
console.log( id1 === id2); // 'false'

Unlike Number, String and Boolean it is not possible to create an explicit Symbol object using the new keyword.


42) Is there a way of checking for equality ?
Yes. You can use the operators (==) and (!=)
The '==' operator checks for implicit type conversion

null == undefined;   // true 
false == 0; // true
'' == 0; // true
'123' == 123; // true
206 != 207; // false

43) Can you explain the following results ?

var a = [1,2,3]; 
var b = [1,2,3];
var c = "1,2,3";
a == c; // true
b == c; // true
a == b; // false

44) Is there a way of checking for equality AND data type ?
Yes. You can use the operators (===) and (!==)
The '===' operator checks for explicit type conversion

null === undefined            // false 
false === 0; // false
'' === 0; // false
123' === 123 // false

let num1 = 10;
let num2 = 10;
console.log( num1 == num2 ); // true
console.log( num1 === num2 ); // true

let num3 = new Number(10);
let num4 = new Number(10);
console.log( num3 == num4 ); // false
console.log( num3 === num4 ); // false

45) Can you describe the 'alert', 'prompt' and 'confirm' functions ?
This displays a message to the user in a modal window.

window.alert('this is a useful message'); 

This displays a textbox asking the user for input in a modal window.
The textbox can have a default value.

var promptResult = window.prompt('This is a prompt for information', 'default value'); 

This displays a question to the user asking them to choose either OK or Cancel.

var confirmResult = window.confirm('Do you confirm?'); 

46) Write a While loop ?
A while loop can execute zero or many times

var x = 10; 
while (x > 0) {
   x--;
   console.log('The value of x is ' + x);
};

47) Write a Do loop ?
A do loop executes at least once.
A do loop contains the keyword while.

var x = 0; 
do {
   x++;
   console.log('The value of x is ' + x);
} while (x > 4);

48) Can you describe the 'break' keyword ?
This provides a way to exit the current loop.
If you are in a nested loop this will only exit one level.

var text = ''";  
for (i = 0; i < 10; i++) {
  if (i === 3) {
      break;
   }
  text += "The number is " + i + "<br>";
};

49) Can you describe the 'continue' keyword ?
This continues with the next statement of the loop.

var text = '';  
for ( I = 0; I < 5; i++) {
   if (I === 3) {
      continue;
   }
   text += 'The number is ' + i + "<br>";
}

50) What is the 'delete' operator ?
The delete operator can be used to delete properties from an object.


51) Can you describe a Function ?
A function is a block of code designed to perform a specific task.
A function is a callable object
A function that is a member of an object is called a method
A function is executed when it is called (or invoked).
A function always returns a value.

function func1() { 
   return 10;
};
console.log( func1() ); // 10

52) Can you describe the 'return' statement ?
If a function contains a 'return' statement the function will stop executing.
If no specific value is returned by this statement then 'undefined' is returned.

function func1() { 
};
function func2() {
   return;
};
console.log( func1() ); // undefined
console.log( func2() ); // undefined

53) How many different ways can you create a function ?
*) Function declaration
*) Function expression
*) Function constructor
*) Arrow function


54) What is the difference between a Function Declaration and a Function Expression ?
Function declarations are hoisted to the top but function expressions are not.
You should always include a semicolon after a function declaraction and a function expression.

// function declaration always starts with the function keyword 
function myfunc1(one, two) {
   return one + two;
};

// function expression with assignment ?
let myfunc2 = function(one, two) {
   return one + two;
};
console.log ( myFunc1(10,5) ); // 15
console.log ( myFunc2(10,5) ); // 15

55) Can you describe the 'Function Constructor' ?
Functions can be defined using the 'function' keyword
Functions can also be defined using a built-in constructor called 'Function'.

var myFunc3 = new Function("one", "two", "return one + two"); 
console.log ( myFunc3(10,5) ); // 15

56) What is a Self-Executing Function ?
This is an anonymous function that is executed immediately and does not pollute the global namespace.
Also called an Immediately Invocable Function Expression ((IIFE).

(function() { 
}) ();

This could be written using the arrow function.

( () => { 
}) ();

The first pair of parentheses converts the function declaration into a function expression.
The second pair of parentheses executes the function.
There is alternative syntax that can be used.

(function() { 
}() ); // douglas crockford

Another alternative is to prefix the function expression with any unary operator


57) Can you explain the difference between 'Assigning' an anonymous function and 'Executing' an anonymous function.

// assigning 
let myfun1 = function() {
}();
// executing
let myfun1 = ( function() {
}() );

58) Can you have Optional Arguments ?
Yes. All arguments are optional by default. If you do not pass in an argument, its parameter will be undefined.
Also if you pass in too many arguments, they will just be ignored.
This has benefits as well as drawbacks.


59) Can you describe the 'arguments' object ?
This is an array-like object that is accessible from inside functions that contains the values of the arguments passed to that function.

function func1 (a, b) { 
   console.log( arguments[0] ); // output: 1
   console.log( arguments[1] ); // output: 2
}
func1(1,2);

60) What is displayed in the Console ?

console.log( mul(2)(3)(4) ); 
function mul (x) {
   return function (y) { // anonymous function
      return function (z) { // anonymous function
         return x + y + z;
      };
   };
};

61) What is displayed in the Console ?

var myObject = { 
   foo: "one";
   func: function(){
      var self = this;
      console.log( this.foo );
      console.log( self.foo );
      ( function() {
         console.log( this.foo ); // this is undefined
         console.log( self.foo );
      }() );
   }
};
myObject.func();

62) Can you describe a Nested Function ?
It is possible to nest function declarations inside function declarations.
Nested functions are private to the function in which they are defined

function multiplySomeNumbers(arg1, arg2) { 
   return doubleThis(arg1) / arg2;
   function doubleThis(arg3) {
      var result = arg3 * 2;
      return result;
   };
};

63) Can you describe an 'Array' ?
All arrays are zero-based by default.

let var1 = []; 
console.log( Array.isArray(var1) ); // added ES 2009

64) How would you return the size of a 1 dimensional array ?
This array is a zero based array.
You can use the length property to return the size of an array.
The length is one more than the highest index

var a = ['dog', 'cat', 'hen'];  
var b = new Array();
b[0] = 'dog';
b[1] = 'cat';
b[2] = 'hen';
b.length; // 3

65) Can you describe the 'push' and 'pop' methods ?
push - appends an item to the end of an existing array
pop - takes an item from the end of the an existing array


66) Can you describe the 'shift' and 'unshift' methods ?
shift - appends an item to the beginning of an existing array
unshift - takes an item from the beginning of an existing array


67) Can you list some Array methods ?



68) Can you list some Array properties ?



69) What is the best way to empty an array ?

var myArray = ['one, 'two','three','four']; 
myArray = []; // ignores any reference variables
myArray.length = 0; // includes reference variables
myArray.splice(0), myArray.length); //includes reference variables

70) Write a For loop to display all the values in an array ?

let myArray = ['one', 'two', 'three'];  
for (let item in myArray){
   console.log( myArray[item] );
}

for (var i = 0; i < myArray.length; i++) {
  console.log( myArray[i] );
}

// forEach method was added in ES 2015
myArray.forEach(function(currentValue, index, array) {
  console.log( currentValue );
});

71) Can you give an example of using 'Array.from' method ?
This method lets you create arrays from arrays-like objects or iterable objects.

Array.from( { length : N } , (v, i) => I ); 

72) Is it possible to start an array at index position 1 (instead of 0) ?
Yes. You can use the Map object (ES 2015) to store key-value pairs

var myArray = new Map( [[1,'one'], [2,'two']] ); 
console.log( myArray.get(2) );

73) What is Object Orientated Programming ?
This is a style of programming that is based on objects containing methods, properties and fields arranged in a hierarchy.
This type of programming is based around four key features:
Polymorphism - Create routines that can operate on objects of different types. This is handled by late binding and multiple interfaces.
Encapsulation - Hide parts of the implementation and hide complexity. This can be achieved using a Module Pattern.
Inheritance (Interface) - (Public Inheritance) Define methods (without implementation) that must be declared in a derived class.
Inheritance (Implementation) - (Private Inheritance) Inherit method implementation from a base class.


74) Is JavaScript an Object Orientated programming language ?
Yes although it is not a class based object orientated language like C#
Polymorphism - Yes because it is not strictly typed
Encapsulation - Yes. Using modules (IIFE)
Inheritance (Interface) -
Inheritance (Implementation) -
No
Inheritance (Implementation) - Can be achieved using prototyping but is at the expense of encapsulation


75) Can you give some examples of built-in Objects ?

global 
Function
Object
Array
Math
Date
RegExp
JSON
Error

76) How many different ways are there to create Objects ?
*) Object Literal
*) Object.create
*) Function constructor
*) ES 2015 class keyword

var ob2 = {};    // preferred 
var obj1 = new Object();

77) Write code to create an Object Prototype ?
Javascript (ES 2009) used functions as classes

function Person(name, age) { 
  this.name = name;
  this.age = age;
};
var you = new Person('You', 24);

78) What are Object Prototypes ?
All JavaScript objects inherit properties and methods from a prototype.
The prototype property allows you to add new properties and methods to existing objects.

function Person( firstname, lastname ) { 
   this.firstname = firstname;
   this.lastname = lastname;
};

// adds a property
Person.prototype.age = 32;

// adds a method
Person.prototype.name = function() {
   return this.firstname + ' ' + this.lastname;
}

79) What is the syntax for accessing object properties ?

obj.name = 'Russell';  
var name = obj.name;
obj['name'] = 'Russell';
var name = obj['name'];

80) What is the 'this' keyword used for ?
The 'this' keyword refers to the object from where it is called.


81) What is a 'closure' ?
A closer is an inner scope which has access to all the variables defined outside of its block.
An inner object does have access to the local variables of its parent function.


82) Can you think of any disadvantages to creating private methods ?
Private methods are very memory ineffcient because a new copy of the method is created for every instance.

var = myClass function(text) { 
   this.name = text;

   // private method
   var myPrivate = function() {
      this.name = this.name.UpperCase();
   };

   // public method
   this.myPublic = function() {
   };
};

83) Write code to add methods to classes ?
It is possible to attach functions to objects

function makePerson(first, last) { 
  return {
    this.first = first,
    this.last = last,

    this.fullName = function() {
      return this.first + ' ' + this.last;
    },

    this.fullNameReversed = function() {
      return this.last + ', ' + this.first;
    }
  };
}
s = makePerson('Russell', 'Smith');
s.fullName(); // "Russell Smith"
s.fullNameReversed(); // "Smith, Russell"

84) How would you create a module using an Immediately Invoked Function Expression ?
This is called "Revealing Module Pattern".
This encapsulates private variables and methods in a closure scope.

var Module = ( function() { 
   var _fullname = "Russell Proctor";
   function setMyPrivateFullName(newValue) {
      _fullName = newValue;
   }
   function getMyPrivateFullName() {
      return _fullname;
   }

   return {
      setFullName : setMyPrivateFullName,
      getFullName : getMyPrivateFullName
   };
}) ();
console.log( Module.getFullName() );
Module.setFullName("Another Name");
console.log( Module.getFullName() );

85) How would you create a module using the CommonJS approach ?
(require and module.exports)
This is the approach used by Node.js

const { a, b} = require('module-name');  
exports.method = str => str.toUpperCase();

86) How would you create a module using the Asynchronous Module Definition (AMD) ?
define and require


87) How would you create a module using ES 2015 ?
The variables and functions in a module are not available anywhere else unless the module explicitly exports them.


88) What is a Promise Object ?
The promise object (or deferred object) is a way of scheduling work to be done on a value that might not yet be obtained.
This lets you write non-blocking logic that executes asynchronously without having to write any plumbing code.
The promise object allows you to chain operations together.
The promise object is implemented in WinJS and JQuery.
The promise object can be in one of three states:
pending -
resolved -
rejected -


89) Write code to create a promise object using JQuery ?
You can create a promise object by using the $.Deferred method.
There are a number of methods available on this Deferred object

resolve - 
resolvewith - passes data to the promises object subscribers
notify -
notifywith - passes data to the promises object subscribers
reject -
rejectwith - passes data to the promises object subscribers
promise -

There are a number of methods available on the Promise object

done - 
fail -
always -
pipe -
progress -
state -
then -

function timeoutAsync(milliseconds) { 
    var deferred = $.Deferred();
    setTimeout(function () { deferred.resolve(); }, milliseconds); //run this code when the time has expired
    return deferred.promise(); // changes the state of the promise object to resolved
};
function abcAsync() {
    var promise = timeoutAsync(2000);
    promise.done(function () { alert('done!') });
    return promise; // you should always return a promise
};

90) Write code that executes if the promise object fails ?
You can use the fail method to execute code if the asynchronous call failures

function abcAsync() { 
    var promise = timeoutAsync(2000);
    promise.fail(function () { alert('failed!') });
    return promise;
};

91) Write code that executes regardless of success or failure ?

function abcAsync() { 
    var promise = timeoutAsync(2000);
    promise.always(function () { alert('this always runs!') });
    return promise;
};

92) Write code that executes chaining using nesting ?
When you want to chain several asynchronous calls together you can nest them

function abcAsync() { 
    var firstPromise = timeoutAsync(2000);
    firstPromise.done(function () {
        var secondPromise = timeoutAsync(3000);
        secondPromise.done(function () {
            var thirdPromise = timeoutAsync(4000);
            thirdPromise.done( function () { alert('done!') } );
            });
        });
    });
    return firstPromise;
};

93) Write code that executes chaining using the pipe method ?

function abcAsync() { 
    var firstPromise = timeoutAsync(2000);
    var secondPromise = firstPromise.pipe(function () {
        return timeoutAsync(3000);
    });
    var thirdPromise = secondPromise.pipe(function () {
        return timeoutAsync(4000);
    });
    thirdPromise.done(function () { alert('done!') });
    return thirdPromise;
};

94) Can you give some examples of JQuery AJAX functions ?
$.get() - load data from the server using a HTTP GET request
$.post() - load data from the server using a HTTP POST request
$.ajax() - perform an asynchronous HTTP (Ajax) request
All these functions and methods use XMLHttpRequest under the hood.


95) Write code to make an asynchronous AJAX call using XMLHttpRequest ?

function fetchAjaxAsync(url, callback, errorCallback) { 
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
      if (xhr.status == 200) {
        processResult();
      }
      else {
        errorCallback(new Error(xhr.statusText));
      }
   }
  }
  xhr.open(url, "GET", true);
  xhr.send();
}

96) Write code to make an asynchronous AJAX call using the Fetch API ?
This API provides a global fetch method (window.fetch)
The Fetch API uses promises so you can chain multiple calls together instead of nesting them.

fetch(url). 
   then( function (response) {
      return response.json()
   })
   .then( function (myJSON) {
      console.log( JSON.stringify(myJSON) )
   })

97) What is Namespacing and how is it used ?
?


98) When should you use the setTimeout, setInterval and clearInterval functions ?
?


99) What are the disadvantages to using innerHTML ?
) content is replaced everywhere
) unable to append to the existing content
) does not provide validation so it is possible to insert invalid HTML


100) Can you explain the 'window.onload' and 'onDocumentReady' events ?
window.onload - this is only run once all the information on the page has been loaded.
onDocumentReady - loads the code after the DOM has loaded.


101) What are some of the new features available in ES 2015 ?
Support for constants
block scope support for constants and functions
classes
promises
arrow functions
enhanced object properties
extended literals
template literals
modules (import /export)
destructuring assignment


102) What is the 'Spread' operator in ES 2015 ?
The spread operator '. . .' can take either an array or an object and expand it into its set of Items.
For arrays this operator lets you drop an array inside another array and get its values.
In the array context, this operator is also called the 'spread element'.

const array1 = [1,2]; 
const array2 = [. . . array1, 3, 4];
// array2 = [1, 2, 3, 4]

For objects this operator is the equivalent of Object.assign, copying the values of one object into a new object.

const object1 = { a:1, b:2}; 
const object2 = { c:3, . . . Object1 };
// object2 = { a:1, b:2, c:3 }

103) Can you explain the difference between Java and JavaScript ?
Java - is a complete and comprehensive programming language
JavaScript - is a client-side scripting language


104) What is JQuery ?
JQuery is a JavaScript library that works across all browsers.
It makes things like HTML document traversal and manipulation, event handling and AJAX much easier.
The library takes common tasks and wraps them into small reusable methods.


105) What is Node.js ?
This platform is built on the Google Chrome JavaScript runtime and lets you write code that executes on the back-end server.
nodejs.org , npmjs.com/package


106) What is NPM ?
Alternatives: Yarn, Bower
This is an abbreviation for Node Package Manager.
NPM is a repository of JavaScript packages (or modules) which can be easily reused by other developers using a command-line tool.


107) What is NPX ?
This is a package runner for Node Package Manager.
NPX was added in NPM 5.2
This is a replacement for installing global packages.
It encourages you to install them locally but still be able to run them as if they were global.


108) What is Webpack ?
Alternative: Browserify
Web Pack is a module bundler for JavaScript applications.
webpack.js.org/concepts
If you need a configuration file when working with webpack you can create a webpack.config.js file in the root folder.
If the file is found webpack will automatically use it.


109) What is Babel ?
Babel is a JavaScript compiler that lets you use JavaScript ES 2015 (ES6) features and transpiles the code to standard ES 2009 (ES5) code.
This lets you use the latest features without worrying about older browsers that do not support ES 2015.

babel-loader 
babel-core

110) What is the Office Fabric-UI ?
The official front-end framework for building experiences that fit seamlessly into Office and Office 365.
This framework implements its components using React.
There is also a JQuery component library and an Angular component library.


111) What is Gulp ?
Alternative: Grunt
Gulp is a JavaScript task runner that can be used to automate repetitive tasks such as minification, unit testing and compilation.


112) What is Transpiling ?
This term means taking source code written in one language and transforming it into another language that has the same (or similar) level of abstraction.
The best example is compiling TypeScript to JavaScript.


113) What is Vue ?
Vue is a JavaScript framework which is being developed and maintained by the open source community.
In the context of MVC (Model View Controller), Vue is just the View.


114) What is Angular ?
Angular is a JavaScript framework being developed by Google.
It lets you extend the HTML syntax to include your components and data binding.
In the context of MVC (Model View Controller), Angular is all three.
Angular1 = Angular JS
The latest version of Angular is called Angular 4.


115) What is TypeScript ?



116) What is React ?



117) What is Material-UI ?
Alternatives: Semantic, Foundation, Evergreen, Prime, Ant Design, Shards, AtlasKit
This is a React UI Framework library being developed and maintained by the open source community.
Version 1 was released May 2018.
These components implement the Google's Material Design guidelines.


118) What is Yeoman ?
This is a command-line scaffolding tool that lets you quickly assemble a web project that has all the required components and dependencies.

npm install generator-office 
yo office

119) What is JSON ?
JavaScript Object Notation is a lightweight data-interchange format and is easy for code to parse and generate.
JSON is built on two structures. A collection of name/value pairs and an ordered list of values.


120) What is YAML ?
YAML is a superset of JSON and is a human friendly data serialisation standard.
This is similar to XML.


121) What is AJAX ?
AJAX is the acronym for Asynchronous JavaScript and Xml
This refers to a set of techniques used on the client side to create asynchronous web applications.



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext