Blog 6 Pick up sticks

Christopher Greene
2 min readJul 18, 2021
  • 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?

409 Conflict
The HTTP 409 Conflict response status code indicates a request conflict with current state of the target resource.

Conflicts are most likely to occur in response to a PUT request.

  • 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?

For adaptive background images, media queries make it simple to tailor the size and resolution of images to a device’s pixel ratio, viewport size and even screen orientation.

By using media queries with our background image styles, we can ensure that only the images that are needed are downloaded from the server. We can limit downloads to the assets that are most appropriate, saving bandwidth, memory and HTTP requests.

  • When should you npm and when should you yarn?

These two package managers are great at managing and maintaining your project dependencies tree. They are reliable, and they have a great and supportive JavaScript community. With the added features, NPM is almost identical to Yarn.

There are not many comparisons to be drawn between the two. You can use Yarn pretty much in every case that you would NPM. It is meant to be a drop-in replacement.

The choice between the two may depend on personal preference, performance (package installations speed), community support, or ease of use.

  • How can you make sure your dependencies are safe?

Of course, there may be malicious code in npm packages. It’s just like installing a software, you do not install random modules. Just make sure the packages you install are trustworthy.

Commands you can run:

npm outdated (for locals) and npm outdated -g — depth=0 (for globals)
This will check which packages are outdated and it will list “Current Wanted Latest” versions for each outdated package.

npm audit
This will produce a report of security vulnerabilities with the affected package name, vulnerability severity and description, etc.

Also, npm audit automatically runs when you install a package with npm install.

npm audit fix
This automatically install compatible updates to vulnerable dependencies.

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

CHAR is fixed length while VARCHAR is variable length. That means, a CHAR(x) string has exactly x characters in length, including spaces. A VARCHAR(x) string can have up to x characters and it cuts off trailing spaces, thus might be shorter than the declared length.

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

In Node.js version 0.10 or higher, setImmediate(fn) will be used in place of setTimeout(fn,0) since it is faster. As such, the code can be written as follows:

console.log(“first”);
setImmediate(function(){
console.log(“second”);
});
console.log(“third”);

--

--