Skip to content

JRLuckett/JS-in-depth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 

Repository files navigation

JS in Depth

Core JavaScript Questions

  1. What is the difference between undefined and not defined in JavaScript?

answer:undefined is the output caused by calling a variable that is declared but not defined.not defined is the output caused by calling a variable that is neither declared or defined.

  1. What is "Hoisting" in JavaScript?

answer: variables are moved to the top of the scope in which they are declared in order to be accessible by all scope attributes

  1. What would be the output of the following code?
    var y = 1;
      if (function f(){}) {
        y += typeof f;
      }
     console.log(y);

answer: y is declared and defined as 1 and f(){} is declared but not defined so the output would be 1undefined

  1. What is a "private method"?

answer: a method that is not accessible globally.

  1. What is the drawback of creating true private methods in JavaScript?

answer: the method takes up a lot of memory because each time an instance of the method is called it is rewritten for the new instance

  1. What is a “closure” in JavaScript? Provide an example.

answer: a closure is function within a parent function that has access to global, parent, and personal variables.

  let globalVar = 1;
  parent = () => {
    inner = 2 * globalVar;
    child = () => {
      innerInner = 3 * inner;
      console.log(innerInner);
    };
  };
  //output 6
  1. Write a mul function which will produce the following outputs when invoked.
console.log(mul(2)(3)(4)); // output : 24
console.log(mul(4)(3)(4)); // output : 48

answer:

  function mul (a) {
  return function (b) {
    return function (c) {
      return a * b * c;
    };
  };
}
  1. How would you empty an array in JavaScript? Provide at least 2 methods of doing so.

answer: array = []; & array = null;

  1. What will be the output of the following code?
var output = (function(x){
    delete x;
    return x;
  })(0);

  console.log(output);

answer: 0

What about this code?

var x = 1;
var output = (function(){
    delete x;
    return x;
  })();

  console.log(output);

answer: 1

And what about this one?

var x = { foo : 1};
var output = (function(){
    delete x.foo;
    return x.foo;
  })();

  console.log(output);

answer: undefined

And finally, what about this one?

var Employee = {
  company: 'xyz'
}
var emp1 = Object.create(Employee);
delete emp1.company
console.log(emp1.company);

answer: xyz

  1. What would this code return?
var trees = ["xyz","xxxx","test","ryan","apple"];
delete trees[3];

  console.log(trees.length);

answer:5

  1. What will be the output of the code below?
var bar = true;
console.log(bar + 0);   
console.log(bar + "xyz");  
console.log(bar + true);  
console.log(bar + false);   

answer: 1, truexyz, 2, 1

  1. What will be the output of the code below?
var z = 1, y = z = typeof y;
console.log(y);  

answer: undefined

  1. What would be the output of the code below?
 var salary = "1000$";

 (function () {
     console.log("Original salary was " + salary);

     var salary = "5000$";

     console.log("My New Salary " + salary);
 })();

answer: Original salary was undefined, My New Salary 5000$

  1. What is the instanceof operator in JavaScript? What would be the output of the code below?
function foo(){
  return foo;
}
new foo() instanceof foo;

answer: an instance operator checks if an object has inheritance from the stated prototype, false.

  1. What constitutes a "Primitive" value in Javascript?

answer: the value is immutable, cannot be changed.

  1. What is the difference between a reference type variable and a value type variable?

answer: reference type variable (pointer) looks to other variables to establish value. A value type variable (holder) holds an established value.

  1. How would you describe the difference between class-based inheritance and prototypical inheritance?

ES6 Questions

  1. What is the difference between JavaScript and ECMAScript?
  2. What do const and let do? And when would we use them?

answer: const defines a variable that will stay constant and cannot be reassigned an new value. let defines a variable.

  1. How would you describe the difference between function and function*?

answer: function* declares a generator function which is a pausable function

  1. When would you NOT use an arrow function in the place of a regular function expression?
  2. Refactor the following code to use an ES6 Template Literal.
var name = 'Tiger';
var age = 13;

console.log('My cat is named ' + name + ' and is ' + age + ' years old.');

answer:

let name = 'Tiger';
let age = 13;

console.log(`My cat is named ${name} and is ${age} years old.`)
  1. How would you refactor the following code to use ES6 default parameters?
function addTwoNumbers(x, y) {
    x = x || 0;
    y = y || 0;
    return x + y;
}

answer:

(x,y) => {
  x = x || 0;
  y = y || 0;
  return x + y;
}
  1. What is a "Promise" in ES6? And how many different states do they have?

answer: A promise (callback) initiates an action once a value is realized. The states are Rending, Fulfilled, and Rejected.

  1. What is a practical use case for Promises?

answer: querying information and once that information is received acting on that value (().then).

  1. What is wrong with the following code? And how could it be better?
new Promise((resolve, reject) => {  
  throw new Error('error')
}).then(console.log)
  1. Describe the .fetch() method. What is one disadvantage to using the .fetch() method over existing methods?

answer: Fetch allows access to the the request and responses pipeline of the HTTP protocol. The .fetch() method will not reject on HTTP error status, it will only reject if the request was not completed. fetch() doesn't maintain user sessions causing possible issues with authentication.

Node.js Questions

  1. What is Node.js?

answer: Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.

  1. What is an "Error-First" Callback?

answer: If there is an error throw and error otherwise return the successful information query.

  1. What is the Node.js Event Loop?
  2. Why might someone choose to use the Node.js Async single-threaded model over a more traditional multi-threaded model?
  3. What is meant by the term "non-blocking I/O"?
  4. What is the "memory stack"? And what happens when you exceed it?

React.js Questions

  1. What makes React.js more efficient at updating the DOM?
  2. What is the difference between a Logical component and a Pure component?
  3. What happens when you call "setState" in React?
  4. What is the React method to create a component? Alternatively, how would you accomplish the same thing using ES6 classes?
  5. In which React lifecycle event would you make AJAX requests? And why?
  6. Why would you use React.Children.map(props.children, () => ) instead of props.children.map(() => )?
  7. What is JSX?

answer: a preprocessor step that adds XML syntax to JavaScript.

Internet/Network Questions

  1. What does TCP/IP stand for?

answer: Transmission Control Protocol/Internet Protocol

  1. Behind the scenes, how does HTTPS differ from HTTP?

answer: All communications between the users browser and the website are encrypted.

  1. Define the general response status code categories.

answer: 200 -> ok, 201 -> created, 204 -> no content, 304 -> not modified, 400 -> bad request, 401 -> not authorized, 403 -> forbidden, 404 -> not found, 409 -> conflict, 500 -> internal server error

  1. What does DDOS stand for?

answer: distributed denial-of-service

  1. What is CORS? How does it work?

answer: Cross-Origin Resource Sharing allows data to be transferred securely across different domains. HTTP headers communicate what actions is to executed on what data.

  1. What does REST stand for when we refer it in the context of a "RESTful API"?

answer: REpresentational State Transfer

About

JavaScript Insight

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages