Javascript Interview + Skills Flashcards
What is Async Javascript?
Asynchronous programming is a technique that enables your program to start a potentially long-running task and still be able to be responsive to other events while that task runs, rather than having to wait until that task has finished. Once that task has finished, your program is presented with the result.
For example, you can start a fetch request, other functions can run. Inside this one function other code will wait for this promise to return
When should you use Json.stringify and json.parse?
For example in the context of sever less functions, when you send your body inside the fetch request to the sever less function, this could be a json string object if you put the content type to JSON string. This can then be received and transformed back to javascript by json.parse.
How does this relate to .json?
JSON.parse and the .json() method in the fetch API are related in that they both deal with JSON data, but they are used at different stages of working with JSON data in JavaScript when making network requests
To extract and parse this JSON data from the response, you can use the .json() method. It reads the response’s body and parses it as JSON, returning a Promise that resolves to the parsed JavaScript object.
JSON.parse is a standalone JavaScript method that is used to parse a JSON string into a JavaScript object. It is not specific to network requests but can be used to parse JSON data from various sources,
What’s Hoisting in Javascript?
Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.
Explain Implicit Type Coercion in JavaScript
Implicit type coercion in javascript is the automatic conversion of value from one data type to another. It takes place when the operands of an expression are of different data types.
What’s the difference between named and default export?
Named export
// moduleA.js
export const foo = ‘Foo’;
export function bar() {
// function implementation
}
// moduleB.js
import { foo, bar } from ‘./moduleA’;
Default export
// moduleC.js
const myDefault = ‘Default Value’;
export default myDefault;
// moduleD.js
import myAlias from ‘./moduleC’;
what’s the difference between slice and splice?
slice returns a piece of the array but it doesn’t affect the original array. splice changes the original array by removing, replacing, or adding values and returns the affected values.
How would you check if a string contains a sub string?
Using includes –> str.includes(‘PHP’)
How do you remove whitespaces from both sides of a string
The trim() method removes whitespace from both sides of a string. JavaScript provides 3 simple functions on how to trim strings.
What’s unshift and shift for used in JS?
Shift –> removes first element, and returns the rest of the array
Unshift –> Add to the beginning of the array