Chandan Kumar

40 posts

Chandan Kumar banner
Chandan Kumar

Chandan Kumar

@krc6893

Full Stack Developer (MERN) | React • Node • MongoDB | Building & learning daily

New Delhi Katılım Ekim 2023
29 Takip Edilen3 Takipçiler
Chandan Kumar
Chandan Kumar@krc6893·
When I started learning web development, HTTP status codes looked confusing. But the idea is simple: 200 means everything is okay. 404 means the page or resource was not found. 500 means something went wrong on the server. 301/302 means the page has been redirected.
Chandan Kumar tweet media
English
1
0
0
10
Chandan Kumar
Chandan Kumar@krc6893·
Add +1 to start from 1 function getRandomNumber(max) { return Math.floor(Math.random() * max) + 1; } Example: getRandomNumber(5) → 1 to 5 Have you used this for games, OTPs, or dice apps? Drop your answer below 👇
English
0
0
0
20
Chandan Kumar
Chandan Kumar@krc6893·
Multiply it by max value 👇 Math.random() * max If max = 5, output can be between 0 and <5 Use Math.floor() to remove decimals: Math.floor(Math.random() * max) Gives values from 0 to 4
English
1
0
0
9
Chandan Kumar
Chandan Kumar@krc6893·
Want to generate a random number in JavaScript? Here’s a simple and useful trick every developer should know 👇 Math.random() gives a random decimal number between: 0 (inclusive) and 1 (exclusive) Example: 0.3482, 0.9271
English
1
0
0
8
Chandan Kumar
Chandan Kumar@krc6893·
function factorial(n) { if (n === 0 || n === 1) { return 1; } return n * factorial(n - 1); } Example: factorial(5) → 120 Recursion or loop — which approach do you prefer? Drop your answer below 👇 #JavaScript #DSA #Coding #WebDev #100DaysOfCode
English
0
0
0
21
Chandan Kumar
Chandan Kumar@krc6893·
If number is 0 or 1, return 1 because: 0! = 1 1! = 1 Recursive Logic 👇 n * factorial(n - 1) Function keeps calling itself until it reaches the base case. Full JavaScript Code 👇
English
1
0
0
24
Chandan Kumar
Chandan Kumar@krc6893·
Want to calculate factorial in JavaScript using recursion? Here’s one of the best beginner-friendly recursion examples 👇 Factorial means multiplying a number by all positive integers below it. Example: 5! = 5 × 4 × 3 × 2 × 1 = 120
English
1
0
0
25
Chandan Kumar
Chandan Kumar@krc6893·
Recursion vs loops Many recursive problems can also be solved with loops. Recursion is often cleaner and more elegant for hierarchical problems, while loops can be more memory-efficient.
English
0
0
0
21
Chandan Kumar
Chandan Kumar@krc6893·
Important caution Without a correct base case, recursion can continue indefinitely and crash with a stack overflow or recursion depth error.
English
1
0
0
23
Chandan Kumar
Chandan Kumar@krc6893·
In programming, recursion is a technique where a function solves a problem by calling itself with smaller or simpler inputs until it reaches a stopping condition. Core idea: A recursive function usually has two parts: #Programming #Coding #JavaScript #100DaysOfCode
English
1
0
0
27