What is the difference between var, let and const
Var is not used anymore
Let for variables and const for constants
What is Compiler, Interpreter
full compile and run vs line by line
what is a loop
allows a block of code to be executed repeatedly based on a specified condition
what is ?
Nested
The ? you see in the code is optional chaining in JavaScript.
It safely checks whether a property exists before trying to access it, preventing runtime errors like:
since some indexes dont have metadata it will cause err
what is a function?
a reusable block of code designed to perform a particular task or calculate a value.
always return the value
what is an object
a standalone entity and a complex data structure used to store collections of data and more complex entities
object methods
keys
values
entries
hasownproperty
assign
anonymous function
const add = (a, b) => a + b;
callback
a function that is passed as an argument to another function, to be executed (or “called back”) at a later time or when a specific event occurs
setTimeout
SetTimeout(fn,time)
what is a constructor
method inside a class which execute automatically
JSON
const user = {
name: “John”,
age: 22,
isStudent: true
};
const jsonString = JSON.stringify(user);
console.log(jsonString);
{“name”:”John”,”age”:22,”isStudent”:true}
Use case: Sending data to a server, storing in localStorage, APIs.
/////////////////////////////////////////////////////////////////////////////
const jsonString = ‘{“name”:”John”,”age”:22,”isStudent”:true}’;
const userObject = JSON.parse(jsonString);
console.log(userObject);
console.log(userObject.name);
{ name: ‘John’, age: 22, isStudent: true }
John
Use case: Reading data from APIs, localStorage, files.
promise
an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value
first argument must be a function
function also need to have the first argument resolve
no callbacks in promises, just return a new promise, an object of promise class
Async Await
.then no need prmoises no need, no callbacks
gfgf