Tuesday, February 7, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home JavaScript

Top 10 Javascript Interview Code-Based Questions(Let’s do brainstorming) | by Ritik Chopra | Nerd For Tech | Aug, 2022

learningcode_x1mckf by learningcode_x1mckf
September 8, 2022
in JavaScript
0
Top 10 Javascript Interview Code-Based Questions(Let’s do brainstorming) | by Ritik Chopra | Nerd For Tech | Aug, 2022
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


If you’re searching for javascript code-based questions for interview observe or brainstorming then I might say you’re on the proper place to study. I’ll attempt to cowl all tough and key questions which aren’t a part of the theoretical Javascript. For higher understanding, I might advocate taking a pen and paper and attempting to unravel it first, might be a superb begin.

1. What would be the output of the beneath code traces?

console.log("11"-1);                          // 10console.log("11"+1);                          // "111"console.log(0 === [[[0]]]);                   // falseconsole.log(0 == [[[0]]]);                    // trueconsole.log(0 === "0");                       // falseconsole.log(0 == "0");                        // trueconsole.log([1,[2,[3,[4,[5]]]]].toString())   // 1,2,3,4,5

2. Tips on how to convert the multi-dimension array right into a 1-D array effectively?

const arr = [1,[2,[3,[4,[5]]]]]
const dArray = arr.toString().cut up(',').map((num) => Quantity(num))

The take a look at array is said to check our code within the first line. Within the subsequent line, we transformed the take a look at array right into a string format after our end result seems like ‘1,2,3,4,5’. the ultimate step can be splitting based mostly on ‘,’ and changing to a quantity.

3. Create 1 to 10 quantity guarantees with random delay and Print them into steady sequence of 1 to 10.

const delay = (val, ms) => new Promise(resolve => setTimeout(resolve(val), ms));const promiseArr = []
for(let i=1; i<=10;i++)
promiseArr.push(delay(i, Math.random()%5));
const end result = Promise.all(promiseArr)
end result.then(res =>
console.log(res) // [1,2,3,4,5,6,7,8,9,10]
)

delay operate creates a brand new promise with a given worth and delay.

The Promise.all() technique takes an iterable of guarantees as an enter and returns a single Promise that resolves to an array of the outcomes of the enter guarantees. This returned promise might be fulfilled when all the enter’s guarantees have been fulfilled, or if the enter iterable comprises no guarantees. It rejects instantly upon any of the enter guarantees rejecting or non-promises throwing an error and can reject with this primary rejection message/error.

4. Tips on how to examine whether or not the thing worth is an object or not?

typeof yourVariable === 'object' && yourVariable !== null

5. Tips on how to create a customized swap in Javascript?

const match = (expr, allCases) => const allCases = 
Hello: 'good morning',
Purple: "colour",
BMW: "my favorite",
default: "not out there"
const matched = match('Hello', allCases)
const notMatched = match('Not', allCases)
console.log(matched) // Good Morning
console.log(notMatched) // not out there

match is a operate which takes all instances and your expression to match in case your expression doesn’t exist then it’s going to discover the default one. allCases is an object of key worth which include our all instances.

6. What would be the output of the beneath code?

const a = Quantity(1)
const b = Quantity(2)
const c = "1"
const d = "2"
console.log(typeof a * b) // NaN
console.log(typeof c * d) // NaN
console.log(typeof a * c) // NaN
console.log((a*b) == (c*d)) // true
console.log((a*b) === (c*d)) // true
console.log(typeof Quantity(a * b)) // quantity
console.log(typeof Quantity(c * d)) // quantity

7. What would be the output of the beneath code?

const arr = [1,2,3,4]
arr.size = 0; // do not do that in your life
console.log(arr) // []console.log("1" - "2" + "3" + "4" * "5")
// first * happens and end result might be
// "1" - "2" + "3" + "20"
// now left to proper move goes
// "-1" + "3" + "20"
// "-1320"

8. We have now three guarantees with the identify and delay, (sluggish, 200), (fast, 50), (immediate, 0), and all ought to resolve on the similar time and order ought to preserve into sluggish, fast, and immediate sequence.

const sluggish = new Promise(resolve => 
setTimeout(resolve, 200, 'sluggish');
);
const immediate = new Promise(resolve =>
setTimeout(resolve, 0, 'immediate');
); ;
const fast = new Promise(resolve =>
setTimeout(resolve, 50, 'fast');
);
const end result = Promise.all([slow, quick, instant])end result.then((res) =>
console.log(res)
)

9. What would be the output of the beneath code?

var a=identify:"RKstar"
var b=identify:"RKstar"
console.log(a===b); // false
console.log(a==b); // false

10. If the array is an occasion of the thing then how will you differentiate an object or array? How a program to make distinction between them?

console.log(diff([]))   // Array
console.log(diff()) // Object
console.log(diff(null)) // Null or Undefined
operate diff(obj)
if(Object.prototype.toString.name(obj) === '[object Array]')
return 'Array'
else if(typeof obj === 'object' && obj !== null)
return 'Object'
else
return 'Null or Undefined'

Some Theoretical and Code-based questions for You, please remark your resolution right here.

what’s the distinction between null and undefined?

Write a JSON parser, can not use inbuilt JSON parser.



Source link

You might also like

An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf

Mimic Javascript actions on identical element? – JavaScript – SitePoint

How To Hire a Professional JavaScript Developer and Find the Best … – Intelligent Living

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

An Introduction to Lodash and Its Benefits for JavaScript Developers  MUO - MakeUseOf Source link

Read more

Mimic Javascript actions on identical element? – JavaScript – SitePoint

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Mimic Javascript actions on identical element? - JavaScript  SitePoint Source link

Read more

How To Hire a Professional JavaScript Developer and Find the Best … – Intelligent Living

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How To Hire a Professional JavaScript Developer and Find the Best ...  Clever Residing Source link

Read more

How to Use Regular Expressions in JavaScript – MUO – MakeUseOf

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Use Regular Expressions in JavaScript  MUO - MakeUseOf Source link

Read more

Web Development & JavaScript Trends in 2023 – Electronicsmedia

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Web Development & JavaScript Trends in 2023  Electronicsmedia Source link

Read more
Next Post
Managing Attributes With Python’s property() – Real Python

Managing Attributes With Python's property() – Real Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Accessible visualization with Olli JavaScript library

Accessible visualization with Olli JavaScript library

October 5, 2022
Raspberry Pi Pico W Bluetooth Support Is Just Around the Corner, for Both C/C++ and MicroPython

Raspberry Pi Pico W Bluetooth Support Is Just Around the Corner, for Both C/C++ and MicroPython

January 4, 2023
Cognizant Offers Five Train-To-Hire Courses on Java through edX.org

Cognizant Offers Five Train-To-Hire Courses on Java through edX.org

September 15, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • C++ Is TIOBE's Language Of The Year – iProgrammer
  • JobRunr, the Java Scheduler Library, Released Version 6.0 – InfoQ.com
  • An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?