Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoFrancis/f6dc2cc8d6dfbe4fe40d95a284618475 to your computer and use it in GitHub Desktop.
Save FrancoFrancis/f6dc2cc8d6dfbe4fe40d95a284618475 to your computer and use it in GitHub Desktop.
In this GitHub Gist, you'll find must-have JavaScript code snippets for beginners. These concise and well-commented examples cover fundamental tasks, perfect for learning and applying in your projects.
1) Reverse a String:
// Reverses a given string
function reverseString(str) {
return str.split('').reverse().join('');
}
2) Working with Arrays:
const myArray = [1, 2, 3];
// Add an element to the end of the array
myArray.push(4);
// Remove the first element from the array
myArray.shift();
3) Check Even or Odd:
// Checks if a number is even or odd
function checkEvenOrOdd(num) {
return num % 2 === 0 ? 'Even' : 'Odd';
}
4) Find the Largest Element in an Array:
const numbers = [10, 4, 6, 8];
// Find the largest element in the array
const largestNumber = Math.max(...numbers);
5) Capitalize the First Letter of a String:
// Capitalizes the first letter of a string
function capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
Explore these snippets and level up your JavaScript skills!
Feel free to experiment with these code snippets in your projects. Happy coding!
@FrancoFrancis
Copy link
Author

Comments and improvements are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment