1)x=10;
console.log(x);
var x=0;
output:10
2)WeakMap
A WeakMap is a built-in JavaScript data structure introduced in ECMAScript 6 (ES6) that allows you to create a collection of key-value pairs where keys are objects and values can be arbitrary data. Unlike Map, keys in a WeakMap are weakly referenced, meaning they don't prevent their associated objects from being garbage collected when no other references to them exist. Here's a brief overview of WeakMap: Usage: WeakMap is used when you want to associate metadata or additional information with objects without preventing those objects from being garbage collected when they're no longer needed elsewhere in your code. Key Characteristics: Keys must be objects (primitive data types like numbers or strings are not allowed as keys). Values can be any type of data. Keys in a WeakMap are weakly referenced, meaning they don't prevent garbage collection of their associated objects. If an object used as a key in a WeakMap has no other references, it may be garbage collected. Methods: set(key, value): Sets the value for the specified key in the WeakMap. get(key): Returns the value associated with the specified key in the WeakMap, or undefined if the key doesn't exist. has(key): Returns true if the WeakMap contains the specified key, otherwise returns false. delete(key): Removes the entry for the specified key from the WeakMap. Weak References: Unlike regular objects, keys in a WeakMap don't prevent garbage collection of their associated objects. This means that if an object used as a key in a WeakMap has no other references, it may be garbage collected. Use Cases: Caching: You can use WeakMap to implement caching mechanisms where you associate cached data with specific objects. Private Data: WeakMap can be used to store private data associated with objects, as the private data can't be accessed from outside the object without a reference to the WeakMap itself. Here's a simple example demonstrating the use of WeakMap: javascript Copy code let weakMap = new WeakMap(); let key = {}; let value = "Some data"; weakMap.set(key, value); console.log(weakMap.get(key)); // Output: "Some data" // Let's remove the reference to the key key = null; // Since the key has no other references, it may be garbage collected. // As a result, the entry in the WeakMap may also be removed automatically. console.log(weakMap.get(key)); // Output: undefined WeakMap is a useful data structure in JavaScript, particularly when you need to associate data with objects without preventing those objects from being garbage collected. However, it's important to be aware of its limitations and use cases to leverage it effectively in your code
3)SQl like?
In SQL, the LIKE operator is used in a WHERE clause to search for a specified pattern in a column. It's often used with wildcard characters (% for matching any sequence of characters, and _ for matching any single character) to perform pattern matching. Here's the basic syntax of the LIKE operator: sql Copy code SELECT column1, column2, ... FROM table_name WHERE column_name LIKE pattern; Example 1: Basic Usage Suppose you have a table employees with a column first_name, and you want to retrieve all employees whose first names start with "J": sql Copy code SELECT * FROM employees WHERE first_name LIKE 'J%'; This query will retrieve all rows from the employees table where the first_name column starts with the letter "J". Example 2: Using Wildcard Characters Suppose you want to retrieve all employees whose first names contain "a" as the second letter: sql Copy code SELECT * FROM employees WHERE first_name LIKE '_a%'; In this query, the underscore _ matches any single character, so it will match any first name where the second letter is "a". Example 3: Case-Insensitive Matching Suppose you want to retrieve all employees whose first names contain "john" (case-insensitive): sql Copy code SELECT * FROM employees WHERE first_name LIKE '%john%' COLLATE SQL_Latin1_General_CP1_CI_AS; In this query, % matches any sequence of characters, so it will match any first name that contains "john" anywhere in it. The COLLATE SQL_Latin1_General_CP1_CI_AS clause specifies case-insensitive comparison. Notes: LIKE comparisons can be slow on large datasets, especially if not used efficiently. Avoid using leading wildcards (% at the beginning of the pattern) with large datasets, as they can't use indexes efficiently. Be cautious with the use of LIKE as it can lead to unpredictable performance, especially on large tables. In some cases, full-text search capabilities provided by databases might be more appropriate. 4)ugrade request: Certainly! Handling upgrade requests, particularly for upgrading to WebSocket protocol, is a process where the client requests to switch from the HTTP protocol to the WebSocket protocol. This is commonly used for real-time communication between a client and a server. Let's break down how to handle upgrade requests to upgrade to WebSocket protocol on a server in Node.js: Create an HTTP Server: First, you need to create an HTTP server using Node.js's built-in http module. javascript Copy code const http = require('http'); const server = http.createServer((req, res) => { // Handle regular HTTP requests here res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, World!'); }); Handle Upgrade Requests: Listen for the upgrade event on the HTTP server. This event is emitted when a client requests to upgrade the protocol. javascript Copy code server.on('upgrade', (req, socket, head) => { // Check if the upgrade request is for WebSocket // (You may want to do additional checks depending on your application) if (req.headers['upgrade'] !== 'websocket') { socket.write('HTTP/1.1 400 Bad Request\r\n\r\n'); socket.destroy(); return; } // Handle WebSocket upgrade here });
5)In sql collection student and projects table .
Need to find all the students having projects which join to use.?The type of join used is an inner join. An inner join returns rows when there is at least one match in both tables being joined. In this case, it will only return students who have projects that require teamwork.
REVOKE ALL PRIVILEGES ON database_name.* FROM 'aram'@'localhost';
Comments
Post a Comment