Posts

Showing posts with the label JS interview questions JS Interview prep

JavaScript Data Types

Let's check the Data Types in JavaScript - Two Categories of Data Types: Primitive Data Types — These are immutable and cannot be modified after creation. a. String: let name = "JavaScript" ; // typeof(name) — 'string' b. Number: let age = 18 ; // typeof(age) — number c. BigInt: console . log ( 9007199254740991n + 1n ); // 9007199254740992n d. Boolean: let truth = false ; // typeof(truth) — boolean e. null: let age = null ; // null f. Undefined: let age; // undefined g. Symbol: let id = Symbol ( 'id' ); Non-Primitive Data Types — These are mutable and can be modified after creation. a. Object: var student = { firstName : "Hello" , lastName : "World" , age : 18 , height : 170 , fullName : function ( ) { return this . firstName + " " + this . lastName ; } }; b. Array: var colors = [ "red" , "green" , "blue" ]; c. Function: function greet ( name ) { return ...

10 JS Interview Prep Coding Problems with solution

Image
  Q1.  Write a function called  sumRange . It will take a number and return the sum of all numbers from 1 up to the number passed in. output expected -  sumRange(3) returns 6 = 1+2+3 Q2.  Write a function called  power  which takes in a base and an exponent. If the exponent is 0, return 1. output expected -  console.log(power(2, 2)); // 4 console.log(power(2, 1)); // 2 console.log(power(2, 0)); // 1 Q3.  Write a function that returns the  factorial  of a number. As a quick refresher, a factorial of a number is the result of that number multiplied by the number before it, and the number before that number, and so on, until you reach 1. The factorial of 1 is just 1. output expected -  factorial(5); // 5 * 4 * 3 * 2 * 1 === 120 Q4.  Write a function called  all  which accepts an array and a callback and returns true if every value in the array returns true when passed as parameter to the callback function output ex...