1. What is GenAI
Generative AI is a type of Artificial Intelligence that can create new content such as text, images, code, audio, and videos based on the data it has learned from.
Examples:
ChatGPT generates text.
GitHub Copilot generates code.
DALL·E generates images.
2. What is constructor function
A constructor function is a regular function used to create multiple objects with similar properties and methods.
A constructor function is a special function used to create and initialize objects. It is called using the new keyword and helps create multiple objects with the same structure.
Example:
function Person(name, age) {
this.name = name;
this.age = age;
}
const person1 = new Person("Kamalesh", 22);
3. What is object
An object is a collection of key-value pairs used to store related data and functionality.
An object is a non-primitive data type that stores data in key-value pairs. It is used to represent real-world entities and organize related data together.
Example:
const student = {
name: "Kamalesh",
age: 22,
course: "AI & DS"
};
4. How do you add a property to an object
We can add properties to an object using dot notation or bracket notation. For example, person.age = 22 adds a new property called age.
Examples:
Dot notation
const person = {
name: "Kamalesh"
};
person.age = 22;
Bracket Notation
person["city"] = "Chennai";
5. What is this keyword
The this keyword refers to the current object that is calling the method. It allows us to access the object's properties and methods from within the object.
The this keyword refers to the object that is currently executing the function.
Example:
const person = {
name: "Kamalesh",
greet: function() {
console.log(this.name);
}
};
person.greet();
6. What is function
A function is a reusable block of code that performs a specific task. It helps avoid code duplication and improves maintainability.
Example:
function greet() {
console.log("Hello");
}
greet();
7. Higher order function
A higher-order function is a function that:
- Accepts another function as an argument, or
- Returns a function.
A higher-order function is a function that either takes another function as an argument or returns a function. Common examples are map(), filter(), and reduce().
Example:
function greet(name) {
return "Hello " + name;
}
function processUser(callback) {
console.log(callback("Kamalesh"));
}
processUser(greet);
8. Synchronous vs Asynchronous
In synchronous programming, tasks execute sequentially and each task waits for the previous one to complete. In asynchronous programming, tasks can run independently without blocking the execution of other code. JavaScript uses callbacks, promises, and async/await for asynchronous operations.
Synchronous
Tasks execute one after another.
Example:
console.log("Task 1");
console.log("Task 2");
console.log("Task 3");
Output:
Task 1
Task 2
Task 3
Asynchronous
Tasks can execute without blocking the main thread.
Example:
console.log("Start");
setTimeout(() => {
console.log("Task");
}, 2000);
console.log("End");
Output:
Start
End
Task
9. Truthy and falsy
Truthy values are values that evaluate to true in a Boolean context, while falsy values evaluate to false. JavaScript has eight falsy values: false, 0, -0, 0n, "", null, undefined, and NaN.
Top comments (0)