Ten JavaScript Interview Questions You have to Know

· There are all the variables that has a value except 0(zero) is true· There are all strings are true except “empty string”.
False, 0, “”,undefined,null, NAN
‘0’, ” ”, [],{},’false’
const variableName = undefined;if(variableName){console.log(“this is true”);}else{console.log(“this is false”);}Output:this is false
· If we not assign a value in variable· Forget to return something from function· Don’t assign all the parameters of the function· Don’t assign a value in the object but read that· Don’t assign a value in the array but read that· If the variable consist a value of undefined
const variableName = 14;if (variableName == “14”) {console.log(“this is true”);}else {console.log(“this is false”);}Output:this is true
const variableName = 14;if (variableName === “14”) {console.log(“this is true”);}else {console.log(“this is false”);}Output:this is false
console.log(name);var name = “naim”output:undefinedvar name = “naim”console.log(name);output:naimlet name = “naim”console.log(name);output:naimconsole.log(name);let name = “naim” //let or constoutput:error
const result1 = counter();const result2 = counter()console.log(result1());console.log(result1());console.log(result2());console.log(result2());console.log(result2());output:
num! =(num)*(num-1)*(num-2)…….*1
const num = 5;let factorial = 1;for (let i = 1; i <= num; i++) {factorial = factorial * i;}console.log(factorial);output:120
function isPrime(number) {for (let i = 2; i < number-1; i++) {if(number%i===0){return “its not a prime number”;}else{return “its a prime number”;}}}const result = isPrime(19)console.log(result);output:its not a prime number
const array = [10, 20, 30, 40];let max = array[0];for (let i = 0; i < array.length; i++) {const element = array[i];if(element>max){max=element;}}console.log(max);output:40
const array = [10, 20,30,14,15,20,40 ,30, 40];let uniqueNumber = [];for (let i = 0; i < array.length; i++) {const element = array[i];const index = uniqueNumber.indexOf(element)if(index==-1){uniqueNumber.push(element)}}console.log(uniqueNumber);output:[ 10, 20, 30, 14, 15, 40 ]




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Turn any Webflow site into Web App easily

Main IMG — Article’s cover

How I started with React — challenges and lessons

Generating Open Graph images with Gatsby

Twitter Bot — reply to any tweet provided as input!

Angular Daily Learning

SockJS + $resource = Awesomeness!

2022. 04. 11 Today I did / Today I learned

Secure a Svelte app & Golang service with Keycloak

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
Md Naimur Rahman Durjoy

Md Naimur Rahman Durjoy

More from Medium

Behind the scenes heroes at Nevada

“Burndown & Control Charts” from an Old Blog

Why SAP? — Why industries use SAP system?

Project 3 — Object Rendering in Rhino