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.

How To Open a Port on Linux

Opening a port on Linux involves configuring the firewall to allow traffic through the specified port. Here's a step-by-step guide to achieve this, assuming you are using ufw (Uncomplicated Firewall) or iptables for managing your firewall settings. u …

read more

Troubleshooting Latency Issues on App Platform

Troubleshooting latency issues on an app platform can be complex, involving multiple potential causes across the network, server, application code, and database. Here’s a structured approach to identifying and resolving latency issues. Identify …

read more