ACA 311 — Week 3 — SQL and Node Timers

Photo by Maksym Kaharlytskyi on Unsplash

♫ Here we go again! Interview questions lightning round! ♫

If a user attempts to create a resource that already exists — for example, an email address that’s already registered — what HTTP status code would you return?

With a bit of digging I’m going to say a “403 — Already Exists’ error would be the most appropriate. A 403 error means the resource can not be created because it already exists. Plain and simple, and the code tells us exactly what went wrong.

Consider a responsive site design that requires a full-width image in all responsive states. What would be the correct way to code this to ensure the page loads the smallest image required to fill the space?

In simple terms, we should use media queries to make sure the browser knows how wide our view-port is and delivers images accordingly. By providing a smaller image both in size and data to smaller screens we can cut download times by only loading the pixels the device is able to display. No wasted download time and all it takes is a little CSS

When should you npm and when yarn?

If I understand the question correctly it is asking when to use npm versus yarn. Both are package managers and I think it’s entirely up to preference. I personally use npm. It’s what I learned starting project development and since the introduction of package-lock.json deciding between yarn and npm is wholly a matter of choice.

How can you make sure your dependencies are safe?

There are tools for automation to keep your dependencies safe, some paid and some free to use. A dependency can be at risk when they become outdated and with huge projects we would have to manually audit each dependency and update them ourselves.

Rather than do that, we can use automation tools like npm outdated, Trace, or NSP to automatically update our dependencies, keeping them secure.

What are the differences between CHAR and VARCHAR data types? (MySQL)

CHAR in SQL is used when the data being stored is always going to be a fixed length. Say we we’re storing a phone number that must always be formatted as 123–4567, we could use CHAR(7) since we’re always storing 7 characters. We would use VARCHAR if we’re unsure about how long the data we’re storing will be, something like an address that isn’t a set length.

How else can the JavaScript code below be written using Node.Js to produce the same output?

setTimeout(function() {
}, 0);

// Output:

// first
// third
// second

We could use the Node.js timer function called setImmediate() like this.

console.log('first');setImmediate(() => {

Think of this function as telling the running code block that the content in within setImmediate() should be run after all other operations in the block have run. In technical jargon, setImmediate() runs at the end of the current event loop cycle. Check out the Node.js documentation for more explanation.

And that’s that for this week.

Austin Coding Academy



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store