Name some of the built-in methods and the values returned by them

JavaScript provides a variety of built-in methods that can be used on different data types. Here are some commonly used built-in methods along with brief descriptions of the values they return:

String Methods:
  1. length:
    • Returns the number of characters in a string.

                    
                        let str = "Hello, World!";
                        console.log(str.length); // Output: 13                    
                    
                

  2. toUpperCase():
    • Returns a new string with all characters converted to uppercase.

                    
                        let str = "hello";
                        console.log(str.toUpperCase()); // Output: "HELLO"                    
                    
                

  3. toLowerCase():
    • Returns a new string with all characters converted to lowercase.

                    
                        let str = "HELLO";
                        console.log(str.toLowerCase()); // Output: "hello"                 
                    
                

  4. substring(start, end):
    • Returns a substring of the original string based on the specified start and end indices.

                    
                        let str = "Hello, World!";
                        console.log(str.substring(0, 5)); // Output: "Hello"                    
                    
                

Array Methods:
  1. length:
    • Returns the number of elements in an array.

                    
                        let arr = [1, 2, 3, 4, 5];
                        console.log(arr.length); // Output: 5                    
                    
                

  2. push(element):
    • Adds an element to the end of an array and returns the new length of the array.

                    
                        let arr = [1, 2, 3];
                        console.log(arr.push(4)); // Output: 4 (new length)                    
                    
                

  3. pop():
    • Removes the last element from an array and returns that element.

                    
                        let arr = [1, 2, 3, 4];
                        console.log(arr.pop()); // Output: 4 (removed element)                    
                    
                

  4. join(separator):
    • Joins all elements of an array into a string, separated by the specified separator.

                    
                        let arr = ["apple", "orange", "banana"];
                        console.log(arr.join(", ")); // Output: "apple, orange, banana"                    
                    
                

  5. indexOf(element):
    • Returns the index of the first occurrence of an element in an array. Returns -1 if the element is not found.

                    
                        let arr = [10, 20, 30, 40, 50];
                        console.log(arr.indexOf(30)); // Output: 2                    
                    
                

These are just a few examples, and JavaScript provides many more built-in methods for various data types. The returned values depend on the specific method used.

SSH Essentials: Working with SSH Servers, Clients, and Keys

SSH (Secure Shell) is a cryptographic network protocol that allows secure communication between two computers over an insecure network. It is commonly used for remote login and command execution but can also be used for secure file transfer and other …

read more

How To Set Up an Ubuntu Server on a DigitalOcean Droplet

Setting up an Ubuntu Server on a DigitalOcean Droplet is a common task for deploying web applications, hosting websites, running databases, and more. Here's a detailed guide to help you through the process. Setting up an Ubuntu server on a DigitalOce …

read more