Skip to main content

deloite

 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.?


ans:



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.




6)let { sa: renamedProperty = 'default' } = name;

In this example, sa is the property in the name object, and renamedProperty is the variable to which its value will be assigned. If sa doesn't exist in the name object, renamedProperty will be assigned the default value 'default'.

7)Sql if aram has some rights in db but not aram leveas the company how to remove rights?
REVOKE ALL PRIVILEGES ON database_name.* FROM 'aram'@'localhost';


8)

In TypeScript, a tuple is a data structure that allows you to store a fixed-size, ordered collection of elements of different types. Tuples are similar to arrays, but with a fixed number of elements and each element can have a different type. They are declared using square brackets [].

Here's a basic example of how to define and use tuples in TypeScript:

typescript
Copy code
// Declare a tuple type
let myTuple: [number, string, boolean];

// Initialize the tuple
myTuple = [10, "Hello", true];

// Access elements of the tuple
console.log(myTuple[0]); // Output: 10
console.log(myTuple[1]); // Output: Hello
console.log(myTuple[2]); // Output: true

// Update elements of the tuple
myTuple[0] = 20;
myTuple[1] = "World";

// Destructuring a tuple
let [num, str, bool] = myTuple;
console.log(num); // Output: 20
console.log(str); // Output: World
console.log(bool); // Output: true
In this example:

We declare a tuple type myTuple with elements of types number, string, and boolean.
We initialize myTuple with values [10, "Hello", true].
We access elements of the tuple using indexing, similar to arrays.
We update elements of the tuple by assigning new values to specific indexes.
We use tuple destructuring to extract values from the tuple into individual variables (num, str, bool).
Tuple types in TypeScript allow you to enforce fixed-length arrays with specific element types, providing type safety and flexibility in handling structured data.









Comments

Popular posts from this blog

Globant part 1

 1)call,apply,bind example? Ans: a. call Method: The call method is used to call a function with a given this value and arguments provided individually. Javascript code: function greet(name) {   console.log(`Hello, ${name}! I am ${this.role}.`); } const person = {   role: 'developer' }; greet.call(person, 'Alice'); // Output: Hello, Alice! I am developer. In this example, call invokes the greet function with person as the this value and passes 'Alice' as an argument. b. apply Method: The apply method is similar to call, but it accepts arguments as an array. Javascript code: function introduce(language1, language2) {   console.log(`I can code in ${language1} and ${language2}. I am ${this.name}.`); } const coder = {   name: 'Bob' }; introduce.apply(coder, ['JavaScript', 'Python']); // Output: I can code in JavaScript and Python. I am Bob. Here, apply is used to invoke introduce with coder as this and an array ['JavaScript', 'Pyt...

Node.js: Extract text from image using Tesseract.

In this article, we will see how to extract text from images using Tesseract . So let's start with this use-case, Suppose you have 300 screenshot images in your mobile which has an email attribute that you need for some reason like growing your network or for email marketing. To get an email from all these images manually into CSV or excel will take a lot of time. So now we will check how to automate this thing. First, you need to install Tesseract OCR( An optical character recognition engine ) pre-built binary package for a particular OS. I have tested it for Windows 10. For Windows 10, you can install  it from here. For other OS you make check  this link. So once you install Tesseract from windows setup, you also need to set path variable probably, 'C:\Program Files\Tesseract-OCR' to access it from any location. Then you need to install textract library from npm. To read the path of these 300 images we can select all images and can rename it to som...

CSS INTERVIEW QUESTIONS SET 2

  You make also like this CSS interview question set 1. Let's begin with set 2, 5)What is the difference between opacity 0 vs display none vs visibility hidden? Property           | occupies space | consumes clicks | +--------------------+----------------+-----------------+ | opacity: 0         |        yes      |        yes       | +--------------------+----------------+-----------------+ | visibility: hidden |        yes       |        no        | +--------------------+----------------+-----------------+ | display: none      |        no       |        no        | When we say it consumes click, that means it also consumes other pointer-events like onmousedown,onmousemove, etc. In e...