git and array[1]
git and array[1]
1. Introduction to Git
Git is a distributed version control system that helps developers track changes to their code and
collaborate effectively. It provides tools to:
1. Save snapshots of code changes (commits).
2. Collaborate with other developers.
3. Revert to earlier versions when needed.
2. Git Workflow
1. Working Directory: Where files are edited.
2. Staging Area: Prepares files for the next commit.
3. Repository: The committed, versioned files are stored here.
git init
• Explanation: Initializes a Git repository in the current folder.
b. Checking Status
git status
• Explanation: Shows the current state of the repository (e.g., modified, staged, or untracked
files).
c. Staging Changes
d. Committing Changes
bash
git log
• Explanation: Shows a detailed log of all commits.
Strings are one of the fundamental data types in JavaScript and are used to represent text. JavaScript
provides a wide range of methods and properties to manipulate and perform operations on strings.
Below is an explanation of the most commonly used string operations, along with examples.
1. String Creation
Strings can be created using single quotes ('), double quotes ("), or backticks (`) for template literals.
javascript
2. String Length
The .length property returns the number of characters in a string.
javascript
3. Accessing Characters
Characters in a string can be accessed using bracket notation ([]) or the .charAt() method.
javascript
4. Changing Case
JavaScript provides methods to change the case of strings:
• .toUpperCase(): Converts the string to uppercase.
• .toLowerCase(): Converts the string to lowercase.
javascript
5. Concatenation
Strings can be combined using the + operator or the .concat() method.
javascript
6. Substring Extraction
• .slice(start, end): Extracts a part of a string.
• .substring(start, end): Similar to .slice(), but does not support negative indices.
• .substr(start, length): Extracts a substring based on the starting index and length
(deprecated but still supported).
javascript
7. Finding Substrings
• .indexOf(substring): Returns the first occurrence index of a substring. Returns -1 if not found.
• .lastIndexOf(substring): Returns the last occurrence index of a substring.
javascript
9. Replacing Substrings
• .replace(oldSubstring, newSubstring): Replaces the first occurrence.
• .replaceAll(oldSubstring, newSubstring): Replaces all occurrences.
javascript
JavaScript provides a rich set of methods to handle and manipulate strings effectively. Mastery of
these operations is essential for tasks like text processing, data formatting, and dynamic content
generation in web development.