Blog 304 — JS311

Meng Fu
2 min readApr 26, 2021
  1. What is “callback hell” and how can it be avoided?
  • Callback hell is when when you write JavaScript visually from top to bottom and there are a lot of callbacks that are not organized and it makes the code messy. It will make your code look like a pyramid. To avoid callback hell, write better and cleaner code. Make your code shallow and easier to read. Give your functions names that are easy to understand and have a meaning.
  1. What are “stubs” in Node.js?
  • Stubs are test spies that can be used to alter a method or functions behavior.
  • Stubs can be wrapped into existing functions. When we wrap a stub into the existing function the original function is not called.
  1. What are “streams” in Node.js?
  • Streams are collections of data. There are readable and writable streams that allow for reading data and writing data. A request to an HTTP server is a stream.
  • However, streams are not only about working with big data. They also give us the power of composability in our code.
  1. What does “chaining” mean in Node.js?
  • Chaining means putting the calls in steps where they run one after the other. Because of Asynchronous code, chaining allows one function or line of code to be ran before the next one is ran. In order to run a code, the one before it has to have already ran and so this allows you to set your callbacks in order and have them run in order.
  1. Explain “console” in Node.js.
  • Console is a global object that allows the code to print different levels of messages such as error messages. There are a lot of different methods that Console gives like console.log() or console.info.
  • Console if also asynchronous which means all the console codes in the code written will be ran in order starting with the first console call and so on.
  1. Explain exit codes in Node.js. List out some exit codes.
  • Exit codes are when you want to exit out of function or code you are running. Process.exitCode =1; is one way to exit if there is a failure. Another way in Node.JS is to use .exit to exit out.
  1. What is the difference between cluster and non-cluster Index?
  • Cluster index is only one per table and faster to read.
  • Non-Cluster Index can have many in the table and it is quicker for update and insert operations.
  1. What are user defined functions? What are all types of user defined functions?
  • User defined functions are routines that accept parameters, perform an action, such as a complex calculation, and return the result of that action as a value.
  • Scalar, table-valued, and system functions are all the types of user defined functions.

--

--