Description: Compares two strings (useful for sorting).
"a".localeCompare("b"); // -1
🔹 27. normalize()
Description: Normalizes Unicode characters.
"é".normalize();
🔹 28. valueOf()
Description: Returns primitive string value.
let str = new String("hello"); str.valueOf(); // "hello"
🔹 29. toString()
Description: Converts object to string.
let str = new String("hello"); str.toString(); // "hello"
🔹 30. Template Literals (`)
Description: Allows interpolation and multi-line strings.
let name = "John"; console.log(`Hello ${name}`);
⚡ Quick Categorization
🔍 Search Methods
includes(), indexOf(), search()
✂️ Extract Methods
slice(), substring(), substr()
🔄 Modify Methods
replace(), replaceAll(), trim()
🔧 Utility Methods
split(), concat(), repeat()
🔡 Case Methods
toUpperCase(), toLowerCase()
🔥 20 JavaScript String Programs (with Solutions)
✅ 1. Reverse a string
let str = "hello"; let reversed = str.split("").reverse().join(""); console.log(reversed);
✅ 2. Check palindrome
let str = "madam"; let result = str === str.split("").reverse().join(""); console.log(result);
✅ 3. Count vowels
let str = "hello"; let count = str.match(/[aeiou]/gi)?.length || 0; console.log(count);
✅ 4. Count consonants
let str = "hello"; let count = str.match(/[^aeiou]/gi).length; console.log(count);
✅ 5. Remove spaces
let str = "h e l l o"; console.log(str.replaceAll(" ", ""));
✅ 6. Convert first letter to uppercase
let str = "hello"; console.log(str.charAt(0).toUpperCase() + str.slice(1));
✅ 7. Find longest word
let str = "I love JavaScript programming"; let words = str.split(" "); let longest = words.reduce((a, b) => a.length > b.length ? a : b); console.log(longest);
✅ 8. Count words
let str = "Hello world JS"; console.log(str.split(" ").length);
✅ 9. Check substring exists
let str = "JavaScript"; console.log(str.includes("Script"));
✅ 10. Replace all vowels with *
let str = "hello"; console.log(str.replace(/[aeiou]/gi, "*"));
✅ 11. Convert string to array
let str = "hello"; console.log(str.split(""));
✅ 12. Remove duplicate characters
let str = "aabbcc"; let unique = [...new Set(str)].join(""); console.log(unique);
✅ 13. Count character frequency
let str = "hello"; let obj = {}; for (let ch of str) { obj[ch] = (obj[ch] || 0) + 1; } console.log(obj);
✅ 14. Check anagram
let a = "listen"; let b = "silent";let result = a.split("").sort().join("") === b.split("").sort().join(""); console.log(result);
✅ 15. Capitalize each word
let str = "hello world"; let result = str.split(" ").map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(" "); console.log(result);
✅ 16. Extract numbers from string
let str = "abc123xyz"; console.log(str.match(/\d+/)[0]);
✅ 17. Check if string contains only digits
let str = "12345"; console.log(/^\d+$/.test(str));
✅ 18. Repeat string N times
let str = "hi"; console.log(str.repeat(3));
✅ 19. Truncate string
let str = "JavaScript"; console.log(str.slice(0, 4));
✅ 20. Convert string to title case
let str = "javascript is fun"; let result = str.split(" ") .map(w => w[0].toUpperCase() + w.slice(1)) .join(" "); console.log(result);
👉 Answer: Reference to original repository (especially in forks).
👉 Use Case: Keep your fork updated with original repo.
Mock Interview: GitHub (Real Company Style)
🔹 Round 1: Basics + Practical Understanding
❓ Q1: Explain your GitHub workflow in your current project.
👉 Strong Answer:
“We follow a feature branch workflow. Each task starts with a new branch from main. After development, we push code and raise a pull request. CI runs automatically using GitHub Actions. After code review and approvals, we merge into main. Direct commits to main are restricted.”
👉 What interviewer checks:
Real experience
Collaboration understanding
CI/CD awareness
❓ Q2: What happens when you run git push?
👉 Strong Answer:
“It uploads local commits from my machine (using Git) to the remote repository on GitHub, making them available to the team.”
👉 Follow-up trap: 👉 “What if push is rejected?”
✔️ Answer:
“It usually means my branch is behind. I pull the latest changes, resolve conflicts if any, and push again.”
🔹 Round 2: Scenario-Based Questions
❓ Q3: You and another developer changed the same file. Your PR shows conflict. What do you do?
👉 Strong Answer:
“I pull the latest changes from main, resolve conflicts locally, test the code, commit the fix, and push again to update the PR.”
👉 Bonus point: Mention testing after conflict resolution.
❓ Q4: You accidentally pushed sensitive data (API key) to GitHub. What will you do?
👉 Strong Answer:
“First, I revoke the key immediately. Then I remove it from the repository, rewrite history if needed, and ensure it’s added to .gitignore. Going forward, I store secrets using GitHub Secrets.”
👉 What interviewer checks:
Security awareness
Real-world handling
❓ Q5: Your teammate’s PR broke the build. What should happen?
👉 Strong Answer:
“The CI pipeline should fail automatically. The PR should not be merged until the issue is fixed. We enforce required checks before merging.”
👉 Extra credit: Mention branch protection rules.
🔹 Round 3: CI/CD + Automation (Very Important)
❓ Q6: How do you integrate automation tests with GitHub?
👉 Strong Answer:
“We use GitHub Actions to trigger Playwright tests on every PR. The workflow installs dependencies, runs tests, and publishes reports.”
👉 Example flow:
PR created
Tests run automatically
Pass → merge allowed
Fail → fix required
❓ Q7: How do you ensure code quality before merging?
👉 Strong Answer:
“We use a combination of:
Pull request reviews
Automated tests
Linting checks
CI validation
Only after all checks pass, the PR is merged.”
🔹 Round 4: Advanced Problem Solving
❓ Q8: Your main branch is broken after a merge. What will you do?
👉 Strong Answer:
“I would quickly identify the faulty commit and revert it using git revert. Then fix the issue in a new branch and raise another PR.”
👉 Important: Avoid rewriting history in shared branches.
❓ Q9: How do you handle multiple environments (dev, staging, prod)?
👉 Strong Answer:
“We use different branches or deployment workflows. For example:
develop → dev environment
main → production CI/CD pipelines deploy automatically based on branch.”
❓ Q10: How do you manage large teams working on the same repo?
👉 Strong Answer:
“We use:
Feature branches
Clear naming conventions
Code owners
Mandatory PR reviews
CI/CD checks
This ensures smooth collaboration and avoids conflicts.”
🔹 Round 5: Rapid Fire (Quick Checks)
❓ Difference between Fork and Clone?
👉 Fork = copy on GitHub 👉 Clone = copy on local machine
❓ What is HEAD in Git?
👉 Pointer to the current commit/branch
❓ What is Rebase?
👉 Rewrites commit history to make it linear
❓ What is Stash?
👉 Temporarily saves uncommitted changes
❓ What is a Tag?
👉 Marks a release/version
🔹 Real Interview Challenge (Hands-On Thinking)
❓ Q11: Design a GitHub workflow for automation testing.
👉 Strong Answer:
“I would:
Trigger workflow on PR and push
Install dependencies
Run Playwright tests
Generate reports
Upload artifacts
Fail build if tests fail
This ensures only tested code gets merged.”
🔹 Final HR + Practical Question
❓ Q12: Tell me a real problem you faced in GitHub and how you solved it.
👉 Sample Answer:
“We had frequent merge conflicts due to long-running branches. I suggested smaller PRs and frequent rebasing. This reduced conflicts and improved deployment speed.”