Javascript Interview + Skills Flashcards

1
Q

What is Async Javascript?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When should you use Json.stringify and json.parse?

A

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,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s Hoisting in Javascript?

A

Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain Implicit Type Coercion in JavaScript

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the difference between named and default export?

A

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’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what’s the difference between slice and splice?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you check if a string contains a sub string?

A

Using includes –> str.includes(‘PHP’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you remove whitespaces from both sides of a string

A

The trim() method removes whitespace from both sides of a string. JavaScript provides 3 simple functions on how to trim strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s unshift and shift for used in JS?

A

Shift –> removes first element, and returns the rest of the array
Unshift –> Add to the beginning of the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly