[Go to site: main page, start]

0% found this document useful (0 votes)
1 views15 pages

JavaScript Interview Guide Gujlish

The document is a JavaScript interview guide that covers essential topics such as data types, scope, functions, and asynchronous programming. It provides detailed explanations along with code examples in a mix of Gujarati and English (Gujlish). The guide is structured into sections that include basics, scope, functions, and objects, aimed at helping candidates prepare for JavaScript interviews.

Uploaded by

prit patel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views15 pages

JavaScript Interview Guide Gujlish

The document is a JavaScript interview guide that covers essential topics such as data types, scope, functions, and asynchronous programming. It provides detailed explanations along with code examples in a mix of Gujarati and English (Gujlish). The guide is structured into sections that include basics, scope, functions, and objects, aimed at helping candidates prepare for JavaScript interviews.

Uploaded by

prit patel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JavaScript Interview Guide

Detailed Explanation with Code Examples


(Language: Gujlish)
Section 1 to 5 | Basics, Scope, Functions, Objects, Async

Section 1: Basics and Data Types

1. JavaScript ma Data Types keva hoy che?


JavaScript ma data types ne be main categories ma divide karvama ave che:

Category Types

Primitive String, Number, Boolean, Undefined, Null, BigInt, Symbol

Non-Primitive Object, Array, Function

Code Example:
// Primitive Types
let name = 'Raj'; // String
let age = 25; // Number
let isStudent = true; // Boolean
let x; // Undefined
let y = null; // Null
let big = 9007199254740993n; // BigInt
let id = Symbol('id'); // Symbol

// Non-Primitive Types
let person = { name: 'Raj', age: 25 }; // Object
let fruits = ['Apple', 'Mango']; // Array
let greet = function() { return 'Hello'; }; // Function

JavaScript Interview Guide (Gujlish) | Page 1


Primitive types immutable hoy che - ek var assign thay pachi teni value badlati nathi.

2. null vs undefined - Shu farq che?

Concept Explanation

undefined Variable declare thayu che pan value assign nathi kari - JavaScript
potane set kare che

null Developer e janine 'khali' value set kari che - intentional empty value

Code Example:
let a; // undefined - value assign nathi kari
let b = null; // null - developer e janine khali rakhu che

[Link](a); // Output: undefined


[Link](b); // Output: null
[Link](typeof a); // Output: 'undefined'
[Link](typeof b); // Output: 'object' (JS nu purana bug!)

// Comparison
[Link](a == b); // true (loose equality - value same)
[Link](a === b); // false (strict equality - type alag)

3. == vs === - Shu farq che?

Operator Description

== (Loose) Sirf value compare kare che, type coercion kare che

=== (Strict) Value AND type banne compare kare che, koi coercion nahi

Code Example:
[Link](5 == '5'); // true (number ne string ma convert kari compare
kare che)
[Link](5 === '5'); // false (type alag che - number vs string)

[Link](0 == false); // true (false = 0 thayu)


[Link](0 === false); // false (number vs boolean)

JavaScript Interview Guide (Gujlish) | Page 2


[Link](null == undefined); // true
[Link](null === undefined); // false

// Best Practice: Hamesha === use karo

4. var, let, const - Shu farq che?

Keyword Scope / Behavior

var Function-scoped, redeclare + reassign banne thai shake che, hoisted

let Block-scoped, sirf reassign thai shake che, TDZ apply thay
const Block-scoped, na redeclare na reassign, declare vakhte value joie j

Code Example:
// var - Function Scoped
function testVar() {
if (true) {
var x = 10; // function scope ma accessible
}
[Link](x); // 10 - block bahar pan accessible
}

// let - Block Scoped


function testLet() {
if (true) {
let y = 20; // sirf aa block ma accessible
}
// [Link](y); // ERROR! y is not defined
}

// const - Immutable Reference


const PI = 3.14;
// PI = 3.15; // ERROR! Assignment to constant variable

const arr = [1, 2, 3];


[Link](4); // OK! Array content badli shakai che
[Link](arr); // [1, 2, 3, 4]

JavaScript Interview Guide (Gujlish) | Page 3


5. JavaScript Single-Threaded che?
Ha! JavaScript ek single-threaded language che. Matlab ek time ma sirf ek j kaam kari shake
che. Pan Event Loop ane Web APIs ni madad thi async operations handle thai shake che -
jema bija operations block nathi thata.

Code Example:
[Link]('1 - Start');

setTimeout(() => {
[Link]('3 - setTimeout callback');
}, 0);

[Link]('2 - End');

// Output:
// 1 - Start
// 2 - End
// 3 - setTimeout callback <-- async hova thi baad ma execute thayu

6. Type Coercion shu che?


Type Coercion etle JavaScript automatically ek type ne bija type ma convert kari de che,
operation perform karva mate.

Code Example:
// Implicit Coercion (Automatic)
[Link]('5' + 3); // '53' - number string ma convert thayu
[Link]('5' - 3); // 2 - string number ma convert thayu
[Link](true + 1); // 2 - true = 1
[Link](false + 1); // 1 - false = 0

// Explicit Coercion (Manual)


let num = Number('42'); // 42
let str = String(100); // '100'
let bool = Boolean(0); // false
[Link](num, str, bool);

7. NaN shu che? Kyare occur thay?


NaN = 'Not a Number'. Jyare invalid mathematical operation thay tyare NaN male che.

Code Example:

JavaScript Interview Guide (Gujlish) | Page 4


[Link](0 / 0); // NaN
[Link]('Hello' - 5); // NaN
[Link]([Link](-1)); // NaN
[Link](parseInt('abc')); // NaN

// NaN ni special property - te potane pan equal nathi!


[Link](NaN === NaN); // false

// Check karva mate isNaN() use karo


[Link](isNaN(NaN)); // true
[Link]([Link](NaN)); // true (better approach)

8. Truthy ane Falsy values shu che?


Falsy values Boolean context ma false return kare che. Baki badhu truthy che.

Falsy Values Truthy Values (Examples)

false, 0, -0, 0n "hello", 1, -1, [], {}

"" (empty string) "0", "false" (non-empty strings)

null, undefined, NaN function(){}, Infinity

Code Example:
// Falsy Values
if (0) [Link]('0 truthy'); // nathi chaltu
if ('') [Link](''' truthy'); // nathi chaltu
if (null) [Link]('null truthy'); // nathi chaltu
if (undefined) [Link]('undef truthy'); // nathi chaltu

// Truthy Values
if (1) [Link]('1 is truthy'); // chalse
if ('hello') [Link]('hello is truthy'); // chalse
if ([]) [Link]('[] is truthy'); // chalse!
if ({}) [Link]('{} is truthy'); // chalse!

Section 2: Scope and Execution Context

9. Scope shu che?


Scope etle te area athva region jya thi variable athva function accessible hoy che.

JavaScript Interview Guide (Gujlish) | Page 5


Scope Type Description

Global Scope Code na baharthi declare - badha j access kari shake che

Function Scope Function ni andar declare - sirf te function andar accessible

Block Scope { } ni andar declare (let/const) - sirf te block andar accessible

Code Example:
let globalVar = 'Global'; // Global Scope

function myFunc() {
let funcVar = 'Function'; // Function Scope

if (true) {
let blockVar = 'Block'; // Block Scope
[Link](globalVar); // OK
[Link](funcVar); // OK
[Link](blockVar); // OK
}

[Link](blockVar); // ERROR! blockVar not defined


}

[Link](funcVar); // ERROR! funcVar not defined

10. Lexical Scope shu che?


Lexical Scope etle variable ni accessibility te par depend kare che ke code kya lakhyu che (not
where it runs). Inner function parent na variables access kari shake che.

Code Example:
function outer() {
let city = 'Ahmedabad'; // outer scope ma declare

function inner() {
// city ne declare nathi karyu pan access kari shake che
[Link]('City:', city); // 'Ahmedabad'
}

inner();
}
outer();

JavaScript Interview Guide (Gujlish) | Page 6


11. Scope Chain shu che?
Scope Chain etle variable ni search process. JavaScript pehla current scope ma shodhse, na
male to parent scope ma, na male to tena parent scope ma - rite global scope sudhi.

Code Example:
let a = 'Global a';

function level1() {
let b = 'Level1 b';

function level2() {
let c = 'Level2 c';

// Scope chain: level2 -> level1 -> global


[Link](c); // 'Level2 c' - current scope
[Link](b); // 'Level1 b' - parent scope
[Link](a); // 'Global a' - grandparent scope
}

level2();
}
level1();

12. Hoisting shu che?


Hoisting etle JavaScript ni evi behavior che jema variable ane function declarations ne
execution pela (memory ma) move kari devama ave che. Actual code move nathi thatu - sirf
memory ma reserve thay che.

Keyword Hoisting Behavior


var Hoist thay, initial value = undefined

let / const Hoist thay pan TDZ (Temporal Dead Zone) ma hoy che - access
karvathi ReferenceError

Function Declaration Fully hoist thay - declaration pela pan call kari shakai che

Function Expression Variable ni jem behave kare che - hoist nathi (declaration pela nahi)

Code Example:
// var hoisting
[Link](x); // undefined (var hoist thay che, pan undefined)
var x = 10;
[Link](x); // 10

JavaScript Interview Guide (Gujlish) | Page 7


// Function Declaration hoisting
greet(); // 'Hello!' - declaration pela pan kaam kare che
function greet() {
[Link]('Hello!');
}

// let - Temporal Dead Zone


// [Link](y); // ReferenceError!
let y = 20;
[Link](y); // 20

// Function Expression - hoisted nathi


// sayHi(); // TypeError: sayHi is not a function
var sayHi = function() { [Link]('Hi!'); };

Section 3: Functions and Functional Programming

13. First-Class Functions shu che?


JavaScript ma functions ne 'first-class citizens' kahevama ave che - matlab functions ne variable
ma store kari shakai che, argument tarike pass kari shakai che ane return pan kari shakai che.

Code Example:
// 1. Variable ma store karvu
const greet = function(name) {
return 'Hello, ' + name;
};

// 2. Argument tarike pass karvu


function execute(fn, value) {
return fn(value);
}
[Link](execute(greet, 'Raj')); // 'Hello, Raj'

// 3. Function mathi return karvu


function multiplier(x) {
return function(y) {
return x * y;
};
}
const double = multiplier(2);
[Link](double(5)); // 10

JavaScript Interview Guide (Gujlish) | Page 8


14. Closure shu che?
Closure etle function che je potana outer function na variables ne 'yaad rakhe che' ane access
kari shake che - bhale outer function execute thai ne complete thai gayu hoy. Closure =
Function + Tenu Lexical Environment.

Code Example:
function counter() {
let count = 0; // outer variable

return function() { // inner function = closure


count++;
[Link]('Count:', count);
};
}

const myCounter = counter(); // counter() execute thai gayo


myCounter(); // Count: 1
myCounter(); // Count: 2
myCounter(); // Count: 3

// count variable bahar thi access nathi thai shaktu - private che!
// [Link](count); // ReferenceError

// Practical Use Case: Data Privacy


function bankAccount(initialBalance) {
let balance = initialBalance; // private variable

return {
deposit: function(amount) { balance += amount; },
withdraw: function(amount) { balance -= amount; },
getBalance: function() { return balance; }
};
}

const acc = bankAccount(1000);


[Link](500);
[Link]([Link]()); // 1500

15. Function Currying shu che?


Currying etle evi technique che jema multiple arguments leta function ne chained single-
argument functions ma convert karvama ave che.

Code Example:
// Normal Function
function add(a, b, c) {
return a + b + c;

JavaScript Interview Guide (Gujlish) | Page 9


}
[Link](add(1, 2, 3)); // 6

// Curried Function
function curriedAdd(a) {
return function(b) {
return function(c) {
return a + b + c;
};
};
}

[Link](curriedAdd(1)(2)(3)); // 6

// Practical Use - Reusable functions


const add5 = curriedAdd(5);
[Link](add5(3)(2)); // 10
[Link](add5(10)(2)); // 17

16. Arrow Functions vs Regular Functions

Feature Arrow vs Regular

Syntax Arrow: const fn = () => {} | Regular: function fn() {}

this keyword Arrow: parent scope nu this inherit kare che | Regular: potanu this
create kare che

arguments object Arrow: available nathi | Regular: available che

Constructor Arrow: use nathi thai shaktu | Regular: new sathe use thai shake che

Code Example:
const obj = {
name: 'Raj',

// Regular function - potanu 'this' hoy che


regularGreet: function() {
[Link]('Regular:', [Link]); // 'Raj'
},

// Arrow function - parent (obj) nu 'this' use kare che


arrowGreet: () => {
[Link]('Arrow:', [Link]); // undefined! (global this)
}
};

JavaScript Interview Guide (Gujlish) | Page 10


[Link](); // Regular: Raj
[Link](); // Arrow: undefined

// Arrow function - useful in callbacks


const nums = [1, 2, 3];
const doubled = [Link](n => n * 2); // concise!
[Link](doubled); // [2, 4, 6]

Section 4: Objects and Prototypes

17. Prototype ane Prototype Chain shu che?


Prototype etle ek object che je bija objects ne properties ane methods inherit karva mate base
tarike kam kare che. Prototype Chain etle search mechanism - current object ma na male to
tena prototype ma, na male to tena parent prototype ma - rite [Link] sudhi.

Code Example:
// Prototype Example
function Animal(name) {
[Link] = name;
}

// prototype par method add karvu - badha instances share karse


[Link] = function() {
[Link]([Link] + ' makes a sound.');
};

const dog = new Animal('Dog');


[Link](); // 'Dog makes a sound.'

// Prototype Chain check


[Link](dog.__proto__ === [Link]); // true
[Link]([Link].__proto__ === [Link]); // true

// hasOwnProperty - check kare che property potani che ke inherited


[Link]([Link]('name')); // true (potani)
[Link]([Link]('speak')); // false (prototype thi inherited)

18. this Keyword JavaScript ma


this keyword current execution context ma object ne refer kare che. Teni value depend kare che
ke function kevi rite call thay che.

Code Example:

JavaScript Interview Guide (Gujlish) | Page 11


// 1. Global Context ma
[Link](this); // Window (browser ma), {} ([Link] ma)

// 2. Object method ma
const person = {
name: 'Raj',
greet() {
[Link]('Hello, I am', [Link]); // 'Raj'
}
};
[Link]();

// 3. call(), apply(), bind() thi this set karvu


function introduce(city) {
[Link]([Link] + ' from ' + city);
}

const user = { name: 'Priya' };


[Link](user, 'Surat'); // 'Priya from Surat'
[Link](user, ['Vadodara']); // 'Priya from Vadodara'

const boundFn = [Link](user);


boundFn('Rajkot'); // 'Priya from Rajkot'

19. Class vs Constructor Function


Code Example:
// Constructor Function (Old way)
function PersonOld(name, age) {
[Link] = name;
[Link] = age;
}
[Link] = function() {
return 'Hello, I am ' + [Link];
};

const p1 = new PersonOld('Raj', 25);


[Link]([Link]()); // 'Hello, I am Raj'

// Class (ES6 - Modern way)


class PersonNew {
constructor(name, age) {
[Link] = name;
[Link] = age;
}

greet() {
return 'Hello, I am ' + [Link];
}

JavaScript Interview Guide (Gujlish) | Page 12


}

const p2 = new PersonNew('Priya', 22);


[Link]([Link]()); // 'Hello, I am Priya'

// Banne same kaam kare che - class ek 'syntactic sugar' j che!

Section 5: Asynchronous JavaScript

20. Event Loop shu che?


Event Loop etle evo mechanism che je continuously monitor kare che ke Call Stack khali che ke
nahi. Khali hoy to Microtask Queue ne pehla ane pachhi Callback Queue ne execute kare che.

Execution Order:

Priority Queue / Task

1st Synchronous Code (Call Stack)

2nd Microtask Queue (Promises, queueMicrotask)

3rd Macrotask Queue / Callback Queue (setTimeout, setInterval)

Code Example:
[Link]('1 - Start'); // Synchronous

setTimeout(() => {
[Link]('4 - setTimeout'); // Macrotask Queue
}, 0);

[Link]().then(() => {
[Link]('3 - Promise'); // Microtask Queue
});

[Link]('2 - End'); // Synchronous

// Output:
// 1 - Start
// 2 - End
// 3 - Promise <-- Microtask pehla
// 4 - setTimeout <-- Macrotask pachhi

JavaScript Interview Guide (Gujlish) | Page 13


21. Promise shu che?
Promise etle ek object che je asynchronous operation nu eventual result represent kare che.
Promise ni 3 states hoy che: Pending (chalti process), Fulfilled (success), Rejected (failure).

Code Example:
// Promise banavu
const fetchData = new Promise((resolve, reject) => {
let success = true;

if (success) {
resolve('Data fetched!'); // Fulfilled
} else {
reject('Error occurred!'); // Rejected
}
});

// Promise use karvu


fetchData
.then(data => [Link]('Success:', data)) // 'Data fetched!'
.catch(err => [Link]('Error:', err))
.finally(() => [Link]('Done!')); // hamesha execute thay

// Promise Chaining
[Link](1)
.then(val => val + 1) // 2
.then(val => val * 3) // 6
.then(val => [Link](val)); // 6

22. async/await shu che?


async/await etle Promise use karva ni modern ane readable syntax che. Te code ne
synchronous jevu dakhave che pan actually asynchronous j hoy che.

Code Example:
// Promise-based approach (old)
function getUserOld(id) {
return fetch('/api/user/' + id)
.then(res => [Link]())
.then(data => data)
.catch(err => [Link](err));
}

// async/await approach (modern)


async function getUser(id) {
try {
const res = await fetch('/api/user/' + id);
const data = await [Link]();
return data;

JavaScript Interview Guide (Gujlish) | Page 14


} catch (err) {
[Link]('Error:', err);
}
}

// Calling async function


async function main() {
const user = await getUser(1);
[Link](user);
}
main();

// Parallel Execution
async function parallel() {
const [user, posts] = await [Link]([
getUser(1),
fetch('/api/posts').then(r => [Link]())
]);
[Link](user, posts);
}

All the best for your JavaScript Interview!

Practice karo, samjo, ane confident raho!

JavaScript Interview Guide (Gujlish) | Page 15

You might also like