Arrow function basics in javascript 😃
Vložit
- čas přidán 6. 09. 2024
- Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.
All the learning resources such as code files, documentations, articles and community discussions are available on our website:
chaicode.com/
You can find our discord link, github link etc on the above website.
Twitter/X link: x.com/hiteshdo...
Discord link: hitesh.ai/discord
Learn React with 10 projects: • Let's learn react from...
Learn Docker: • A practical guide on D...
Learn Kubernetes: • Complete Kubernetes Co...
How does a browser works: • How does a browser wor...
How nodejs works: • How node JS works | En...
Learn Redux-toolkit: • Learn Redux Toolkit in...
Learn NextJS: • Nextjs Full stack course
Learn Typescript: • Why to learn Typescript
Learn Javascript: • Welcome to new JavaScr...
Learn React Native: • React Native Mastery: ...
Learn Zustand: • React state management...
Learn Golang: • How to get started wit...
const todo = [{
title: 'Learn coding',
isDone: true,
},{
title: 'Work-Out',
isDone: false,
},{
title: 'Go to office',
isDone: true,
},{
title: 'meet customer',
isDone: false,
},{
title: 'Drive home',
isDone: true,
},{
title: 'collect laundry',
isDone: false,
}]
let thingsNotDone = todo.filter((todo) => todo.isDone === false)
for (var i = 0; i < thingsNotDone.length; i++) {
console.log(thingsNotDone[i].title)
}
This one definitely works but hope this is the intended solution.
Thank you Hithesh for your effort. Appreciate it
How many of u are here after quarantine**
Well documentations are really helpful when you know how to look upon them.
const titleNotDone = myTodos.filter(todos => todos.isDone === false)
.map(todos => todos.title)
Assignment :
const ThingsNotDone = todo.filter((todos) => todos.done === false);
ThingsNotDone.forEach((things) => console.log(things.title));
const notDone = todos.filter((todo) => todo.isDone === false);
notDone.forEach(todoo => console.log(todoo.title));
Tnx bro .
@@atanumondal4109 thnx bro
got output but also its shown undefined in output
Its being over 2 years now and JS has evolve try and read updated documentation of JS. You should see the evolvement.
//Assignment code for the video
------------------------------------------------------------------------------------------------------------------------------------
const newTodo=[
{
title:'Brush',
isDone:true,
},
{
title:'Bath',
isDone:true,
},
{
title:'Breakfast',
isDone:false,
},
{
title:'Catch up bus',
isDone:true,
},
{
title:'Complete assignment',
isDone:false,
},
{
title:'Study',
isDone:false,
}
]
const todo=newTodo.filter((param)=>param.isDone===false
)
for (let i = 0; i < todo.length; i++) {
console.log(todo[i].title)
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------
//Object array
const toDos = [{
title: "Morning Gym",
isDone: true
},{
title: "Morning Yoga",
isDone: true
},{
title: "Meetings",
isDone: false
},{
title: "Lunch meet",
isDone: false
},{
title: "Assignments",
isDone: true
},{
title: "UI design",
isDone: false
}]
//Filter logic using Arrow function
const notDone = toDos.filter((todo) => {
if(todo.isDone === false)
{
console.log(todo.title)
}
});
//Calling the method
notDone;
you are awesome,if i visit to india the first person to meet will be you.
thnks for videos.....................keep this on..
This really explain the arrow function is! Thanks Hitesh
Heres my code: todos.filter((todo) => todo.isDone == true).map((todo) => todo.title)
I am a Java developer and want to learn Javascript. Your courses are super helpful.
const findTrueTodo = myTodos.filter((todo) => {
if( todo.isDone === true ){
console.log(todo.title)
}
})
Working code
ps: Make changes in variable name according to your needs
Here's the full code ..
const todos = [ {
title:'Brush Teeth',
status:"done",
} , {
title:'Bath',
status:"done",
} , {
title:'Eat breakfast',
status:"done",
} , {
title:'Eat Lunch',
status:"notDone",
} , {
title:'Eat dinner',
status:"notDone",
} , {
title:'Sleep',
status:"notDone",
} ]
let thingsNotDone = todos.filter((todos) => { if(todos.status == "notDone" ){console.log(todos.title);}})
Your way of teaching style is so clear and easy
you are the best teacher as well as best programmer.The way of explaining coding concepts are very simple.... I have no words to say about you 🤔
Edited-
const Todos=[{
title: 'Title1',
isDone: true,
},{
title: 'Title2',
isDone: false,
},{
title: 'Title3',
isDone: true,
},{
title: 'Title4',
isDone: false,
},{
title: 'Title5',
isDone: true,
},{
title: 'Title6',
isDone: false,
}]
const result = Todos.filter((todo) => todo.isDone === false)
result.forEach(todo => console.log(todo.title));
Your very likeable personality makes your videos easy and fun to learn! Blessings from D.C!
const result = todos.filter((todo) => todo.isDone == true ? console.log(todo.title) : false);
Thanks, Hitesh for the wonderful basic videos. keep uploading!
Trying to learn this while sick doesn't help, but had fun figuring it out.
const todoDone = todos.filter((todos) => {if (todos.notDone === true) {console.log(todos.title)}})
bro its showing an empty arry
I am currently watching a react native tut online and I was totally lost, but thank God you posted this video. I wish I can link the video to the tut... thanks alot
const doneThings = function(todo, trueOrFalse)
{
const titleReturn = todo.filter((todo)=>todo.isDone === trueOrFalse);
return titleReturn;
}
doneThings(newTodo,false).forEach((todo) => console.log(todo.title))
Literally the hardest way possible to solve this, but it's good
"use strict";
let toDoList = [{
title: "Have a Breakfast",
isDone: false
}, {
title: "Smile:)",
isDone: true
}, {
title: "Brush your teeth",
isDone: false
}, {
title: "Go to the gym",
isDone: false
}, {
title: "Have a good sleep",
isDone: true
}, {
title: "Start learning plain js",
isDone: true
}];
function leftToDoFilter(list) {
let filtered = list.filter( (item) => item.isDone === false );
let filteredTitle = [];
filtered.forEach( item => filteredTitle.push(item.title) );
return filteredTitle;
}
console.log(leftToDoFilter(toDoList));
That's a great explanation. It would be amazing if you explain the purpose of arrow functions in the code.
*Not able to print the Objects* inside the Array. It only printing ' [ ] ' . Not printing isDone Objects. Why it is so? I have used VSCode, console also.
const completedTasks = todo.filter(task => task.isDone).map(task => task.title);
Nice
nice explanation it helps very lot to beginners , I done u r assignment and can u share the difference b/w the "arrow function" and "js function" ,arrow function have more properties compare to js function
var todo = [
{title:"First",isDone:true},
{title:"Second",isDone:false},
{title:"Third",isDone:true},
{title:"Fourth",isDone:false},
{title:"Fiveth",isDone:true},
{title:"Sixth",isDone:false}
];
todo.filter((x)=>{ if(x.isDone === true){console.log(x.title)}});
Well explained ❤
I just love your content brother. Lots of love for you.
Thanks for the simple explanation of arrow functions appreciate it. Taking it nice and slow allowed me to understand it :)
Great video. Nice and easy to follow and understand. Thank you Hitesh.
I think i m in love with Arrow functions 😂 #js love
Assignment:
let thingsNotDone = things.filter((todo)=>{
if(todo.isDone == false)
console.log(todo.title);
});
//Create a tudo with 6 objects using filter to get things not done. Print only title of the job to do.
const myTudos=[{name:'Play',done:false},{name:'Eat',done:false},{name:'Read',done:false},
{name:'Talk',done:true},{name:'Walk',done:true},{name:'Sleep',done:true}];
let find_not_done=function(tudos){
const not_done=tudos.filter((tudo)=> tudo.done===false)
not_done.forEach((nd)=>console.log(`You have not done : ${nd.name}`))
}
find_not_done(myTudos);
why aren't we using simple loop inside a function to check the true entries ?
it will be easier that way around!
const todos = [{
title: 'Wake up',
isDone: true
}, {
title: 'breakfast',
isDone: true
}, {
title: 'studying',
isDone: false
}, {
title: 'go to park',
isDone: false
}, {
title: 'lunch',
isDone: true
}, {
title: 'go to gym',
isDone: false
}]
let workNotDone = todos.filter( (todo) => todo.isDone === false).forEach((todo) => console.log(todo.title))
mySchedule.filter((mySchedule)=> mySchedule.isDone === true).forEach((objs)=> console.log(objs.title))
const notDone = todos2.filter((todo) => todo.isDone === false);
for(var i = 0; i
just use forEach, no point in setting up a for loop for this
Thanks for the video Hithen, Is there any performance difference between function declaration without using Fat Arrow function and the one with Fat Arrow function ?
After creating the todo list, this one line will surely sort the titles out for notDone
todo.filter( (eachTodo) => eachTodo.isDone === false ? console.log(eachTodo.title) : null )
Clear explanation and learned about the filter() function, thanks :D
Thank u buddy for your wonderful explanation in arrow function.Understood well.
//printing title using for loop
const notDone = Todos.filter((todo) => todo.isDone === false)
for (var i =0; i < 3; i++){
console.log(notDone[i].title)
Ans works
I jus want to understand this, Why are you using CONST instead of Let? CONST is constants right? Please clarify.
const denote constants. They do not change their value during execution (try and change it, you'll get an error).
let taskDone = todos.filter(todo => !todo.isDone).map(todo => todo = todo.title)
const thingsNotDone = todos.filter(todo => todo.isDone == false).map(todo => todo.title)
Thanks for the explanation! Good and clear video
there is only one parameter you are passing.... so you can remove those parentheses around name......
instead of .. const sayHello = ( name ) => `hey there ${name}`
you can write ... const sayHello = name => `hey there ${name}`
const notDone = myTodos. filter((todo) => todo.isDone === false )
notDone.forEach((unDone) => console.log(unDone.title))
const todosNotDone = todos.filter((todo) => todo.isDone === false).map((todo) => todo.title);
Combining filter and map method together.
Very clear explanation, thank you!
I am getting No debugger available, can not send 'variables' is error in my console
I always prefer arrow function and make code small but I hate when someone call it big fat arrow its
disrespectful
Hi bro! Your way of explaining things is very easy to follow and understand. I occasionally see your clip and most of the time found what I was looking for. Your explanation about Arrow Function in JavaScript helped me to have a cleater understanding on the topic as I am a beginer of JavaScript. Thank you.
Is arrow function and lamda function same
ASSIGNMENT
const isNotDone = myTodos.filter((todos) => todos.isDone === false)
const checkIfDone = isNotDone.forEach(todos => {
console.log(todos.title)
});
It's a really great video man I can't thank you enough It was for me really hard to understand this with arrow with function but now you make it really semple
Thanks
Thanks for all the things, what is the actual need of using *const* in starting of program....
Very helpful
Hey Hitesh....Is arrow funtion => is as same as lambda expression in Java8 ?
Can someone tell me what is wrong with the below code. It returns undefined.
const showToDo = toDoList.filter((todo)=>todo.isDone === true);
const showToDoTitle = showToDo.forEach(todo=>todo.title);
console.log(showToDoTitle);
Which font you are using?
enjoyed the video
Wonderfull
todos.filter(todo => !todo.isDone).forEach(thing => console.log(thing.title))
Superb!
let a=5,b=5;
var sample=()=>
console.log("hello");
if(a==b){console.log(a+b);}
console.log("hello");
sample();
output : 10 hello hello
/ let a=5,b=5;
// var sample=function(){
// console.log("hello");
// if(a==b){console.log(a+b);}
// console.log("hello");
// }
// sample();
output: hello 10 hello
how is posssible can anyone plz explain???
const notDone = todos.filter((todo) => todo.isDone === false)
console.log(notDone.map(test=>test.title))
you never said about the binding of the "this" with the arrow function
There must be a better way, what is it?
------
const thingsNotDone = todos.filter(todo => !todo.isDone)
thingsNotDone.forEach(thing => console.log(thing.title))
You can run forEach on filter result itself, don't consider creating mid level variable. Just small enhancement
todos
.filter( todo => !todo.isDone )
.forEach( todo => console.log( todo.title ));
const things = todo.filter ( function (ctr){
if (ctr.done === false)
return ctr.name
})
console.log(things)
//This gives me the entire object within the array which is false, even though I'm returning ctr.name.
Can anyone tell me why?
const lists = [{
title : "Waked up in morning",
isdone : true,
},
{
title : "eat breakfast",
isdone : true,
},
{
title : "roam outside",
isdone : false,
},
{
title : "watch tv",
isdone : false,
},
{
title : "play cricket",
isdone : true,
},
{
title : "scored century",
isdone : false,
}];
const result = lists.filter((list) => {
return list.isdone === false;
}); // stored in a variable
result.forEach((value) => {
console.log(value.title); // performing forEach in the stored variable and printing value with title.
});
can anyone help me... thanks in advance
const itemsTrue = [
{title:'item1',isDone:false },
{ title:'item2', isDone:true},
{title:'item3', isDone:true},
{ title:'item4', isDone:false},
{ title:'item5', isDone:false},
{ title:'item6', isDone:true},
]
const things = itemsTrue.filter((i) => i.isDone === false )
document.write(things);
it show's o/p = nothing why
2. when i change it to ( let things) variable ---- it show's = [object Object],[object Object],[object Object]
const thingsDone = todo.filter(ele => ele.isDone=== false).map(ele=>ele.title);
Good Day Sir, screen recording ke liye konsi software use karte hai aap? Kya aap bata sakte hain..... please......
// My todo list
const todos = [{
title: 'Complete lecture list',
isDone: false,
}, {
title: 'Practice lecture assignments',
isDone: true,
}, {
title: 'Drink ice tea',
isDone: false,
}, {
title: 'Practice little more',
isDone: true,
},{
title: 'Do some fun things',
isDone: false,
}, {
title: 'Morning exercise',
isDone: true,
}]
//Filter will itterate through all todos and if function condition returns true //it will create new array for them and will return it
const remainingWork = todos.filter(function (todo){
if (!todo.isDone){
return true;
}
});
//It will log the remaining todos title
remainingWork.forEach(function(todo){
console.log(todo.title);
});
I am learnt programs in CZcams n also practiced. When trying to write own programs I don't getting ideas. Please help me sir
return 'hello ${name}!' is not returning the name i pass.. it just printing hello ${name} !
const todoDone = todos.filter((todo) => {
return todo.isDone === true
})
console.log(todoDone.title)
why is it wrong? Showing "undefined" error.
Because todoDone is a variable not an object
(todoDone.title) in case you defined todoDone as an object.
is arrow function similar to the lemda expression in java or python.
const notDone = todos.filter((todo)=>todo.isDone === false)
notDone.forEach((todo) => console.log(todo.title));
Hi Hitesh, can we use lambda expression to return values as well in JS. I use to do such things in my C# using .Select. But is there something like that in JS (was working with assignment and trying to wrap up in single line).
When I use document.write(thingsDone) , the output shows word object , I did not understand why it does not print contents of objects
Hi Nirbhai, 'thingsDone', is an array, not plain text or number or bool. So when we say document.write it will say it's not object. You can console.log to print that array on console. Console API check it's that's array and will print every element inside array. Or if you want to print of document only, you need to convert the array to single string, that we can do by calling JSON.stringify.
const thinsAreDone = todos.filter( todo =>{
if(todo.isDone === false){
return todo.title
}
})
let fil = todos.filter((todo) => !todo.isDone)
fil.forEach ((todo) => console.log(todo.title))
const thingsNotDone = todos.filter((todo) =>
{
if(todo.isDone === false){
console.log(todo.title);
}
})
const notDone = todos.filter((todo)=>{
if(todo.title===false)
return console.log(todos.title);
This makes sense. optimized code
const thingsNotDone = todos.filter((todo)=> todo.isDone === false)
thingsNotDone.forEach(todo =>console.log(todo.title) )
const titleRun =ass.filter((ass)=>ass.isDone===true)
titleRun.forEach(function(titleRun,index){
console.log(titleRun.title)
})
Using If
const notDone = todos.filter((todo) => {
if(todo.isDone === false){
console.log(todo.title);
}
});
I just cant't seem to run my javasript file in my terminal of MS code, tough I have installed node.js
Also provide me notes also sir
const thingsUndone =todo.filter((todo)=>
{
if(todo.isDone===false)
console.log(todo.title)
})
So we can call it a lambda function?
why u always decalre function as const ????????????????
Can I use the arrow function on forEach?
And how do I write the arrow function without any parameters?
1. LiskOfTask.forEach(task=>console.log(task.tititle))
2. let greeting = ()=> console.log('Hi there');
thanks!
console.log(thingsdone.map(({title})=> title))
todos.filter((todo)=>{
let a=todo.isDone;
if(a===false){
console.log(todo.Title)
}
} );
Quick question : react native android app is made in android studio or in something else sir?
Most on (Sublime/Atom/VScode) and for running the app you can use your phone with expo app.
Same as lemda function of Java
use if to do in simple way
const thingsNotDone = todos.filter((todo) => todos.isDone === false)
console.log(thingsNotDone);
can anyone please tell me why is this not working ?
Use ... todo.isDone in place of todos.isDone
//tried one more (this returns the array)
//------------------------------------------------------------
const thingsNotDone = (todo) =>{
let result= [ ]
todo.filter((e) => {
if(!e.isDone) return result.push(e.title)
//console.log(e.title);
})
//console.log(result)
return result
}
thingsNotDone(myTodo).forEach(e=>console.log(e))