IRC log of #novawebdev for Wednesday, 2023-10-11

*** shmohamud has quit (Ping timeout: 480 seconds)00:34
*** shmohamud has quit (Ping timeout: 480 seconds)01:28
*** shmohamud has quit (Ping timeout: 480 seconds)04:20
*** scooper has quit (Ping timeout: 480 seconds)06:42
*** sysadmin has quit (Ping timeout: 480 seconds)07:02
*** sysadmin has quit (None)07:05
scooperACTION signing up still tomorrow same time11:21
*** scooper has quit (Quit: Leaving)11:22
*** scooper has quit (Quit: Leaving)12:30
*** shmohamud has quit (Remote host closed the connection)19:45
*** shmohamud has quit (Remote host closed the connection)19:54
scooperHello Shmohamu19:55
*** shmohamu_ has quit (Remote host closed the connection)19:57
shmohamudhi scooper20:05
scooperhi shmohamud20:05
scooperI m here now20:06
shmohamudAwesome20:07
shmohamudSo, did I give homework last time?20:07
scooperhmmm no20:07
shmohamudOk, do you have any questions for me before we review last time?20:08
scooperyes20:08
shmohamudlets hear it20:08
scooperSo we you mentioned the different type of function in JS20:09
scooperSo you mentioned the different type of function in JS20:09
shmohamudyes20:09
scooperWhich one is mostly use and mostly consider??20:10
scooper(function myFirstFunction(){ } myFirstFunction();20:11
scooperfunction myFirstFunction(){ } myFirstFunction();20:12
scooper(function myFirstFunction ()=>{ } myFirstFunction(); arrow function20:12
scooperthe above three function I mentioned which one is mostly consider???20:13
shmohamudI don't know which one is more widely used, but I think today more people use arrow functions as opposed to function declarations20:13
scooperOK20:14
shmohamudwhat I do know is that it's important for you to know arrow functions and function declarations because they're both widely used20:14
scooperok20:14
shmohamudDifferent scenarios require different functions. If you need the function to be "hoisted" then use a function declaration. If you're defining a callback, arrow functions are often used because the syntax is shorter20:15
shmohamudcan you write me a function called addNumbers that has two parameters, a and b, and it console.log(a + b)20:17
shmohamud?20:17
scooperok20:18
shmohamudyou can do function declaration or arrow function, whichever you prefer20:18
scooperconst function addNumber(a,b){20:25
scooperconsole(a+b)20:25
scooper}20:25
scooperaddNumber(4,5):20:25
scooperplease hold on a came with an error20:25
shmohamudwhen you declare a function do you need the const keyword?20:26
scooperno20:26
scooperI think I should have use let or var20:27
scooperbecause const don't allow redeclaration right???20:27
shmohamudYou can use any of them but only if you're writing a function express. Like const addNumbers = function(a,b){ }20:27
shmohamudvar addNumbers = function(a,b){}20:27
shmohamudlet addNumbers = function(a,b){}20:28
shmohamudbut that's for function expressions. When you declare a function, there's no need to add const/let/var at all.20:28
shmohamudJust keep it as function addNumbers(a, b){ }20:28
scooperok20:29
shmohamudthere's one more error. Do you see it?20:29
scooperIn my function??20:30
scooperdefinition20:30
shmohamudin the function body20:31
shmohamudwhat happens when you try to run it?20:31
scooperit cause a typo error20:32
shmohamudpaste the code you're running here20:32
scooperI got it20:33
scooperconst addNumber = function(a,b){20:33
scooper    console.log(a+b)20:33
scooper    20:33
scooper}20:33
scooperaddNumber(4,5)20:33
shmohamudnice, what was the error?20:33
scooperthe error can from the way I first define the function20:34
shmohamudwhat in the function body was incorrect?20:34
scooperinstead of console.log I had console20:35
shmohamudexactly20:35
shmohamudthat's what I wanted to hear! How did you catch the error?20:35
scooperyes20:35
scooperSorry you asking a question???20:37
shmohamudLol yes I'm asking a question --- how did you know to change console to console.log?20:37
shmohamudDid the error message help you at all? I'm asking because it's a key skill you must learn is to read error messages and learn what they mean20:38
scooperbecause I went through my code line by lines20:38
scooperyes the error message help me too20:38
shmohamudGood20:38
scooperbecause it said type error20:38
scooperbecause it say typo error20:39
shmohamudNow can you rewrite the same function, except this time don't make it a function expression, keep it as a function declaration. Can you do that?20:39
scooperok20:39
scooperlet me try20:40
scooperconst addNumber = function(){20:41
scooper    console.log()20:41
scooper}20:41
scooperaddNumber();20:41
shmohamudis that a function declaration or a function expression?20:42
scooperhmmm it's a function declaration because the function don't have20:44
shmohamudNo, it's a function expression because you're setting a variable equal to the function declaration.20:44
scooperparameter and an argument though it have print statement and a function call20:44
shmohamudAnytime you see an equal sign and a function it's a function expression20:44
shmohamudfunction expressions and function declarations can both have parameters in the definition20:45
scooperwhat if I do this20:45
scooperconst addNumber function(){ console.log}addNumber():20:46
shmohamudclose, but do you need to put the const there?20:46
shmohamudalso, why did you remove the parameters and arguments?20:47
scooperbecause I m declaring a function that why20:47
scooperin JS to declare something you need to use the follow reserved key word20:47
scooperlet, var or const20:47
shmohamudYou don't need to use const , var, let when you're declaring a function20:47
shmohamudtry it and see for yourself :)20:48
scooperok20:48
scooperncaught SyntaxError: Unexpected token 'function'20:49
scooperI received error20:49
scooperaddNumber function(){20:49
scooperconsole.log()20:49
scooper}20:49
scooperaddNumber();20:49
shmohamudthat's because you must put function before the name of the function. So function addNumber20:49
scooperhmmm it work20:51
scooperfunction addNumber(){20:51
scooper    console.log()20:51
scooper}20:51
scooperaddNumber();20:51
shmohamudcan you add back the parameters and make sure to call it with arguments?20:51
shmohamudSee if that works ... 20:52
scooperit seems to be a bit tracky here20:52
scooperlet me give it a try20:52
scooperfunction addNumber(a,b){20:53
scooper    console.log(a+b)20:53
scooper}20:53
scooperaddNumber(4,10);20:53
shmohamuddid that work?20:53
scooperyes20:54
shmohamuddid you need to add let, var, const to declare the function?20:54
scooperI got an output of 14 in the 20:54
scooperfrom what I did, I didn't think so it really necessary20:55
shmohamudYes, you don't need let, var, const to have a function declaration20:56
scooperNow I know, thanks Sahnun20:56
shmohamudOf course, way to stick with the question. This is tricky stuff.20:57
shmohamudSo, do you have any questions for me?20:57
scooperyes20:57
shmohamudlets hear it20:57
scooperlet me get something clear here, in python we use indentation for a particular block so, can I consider curly bracket to be js own of indentation??20:58
shmohamudYes, the syntax to declare a function block is that it must go in curly brackets (unless it's a special kind of arrow function, which we will discuss later)20:59
shmohamudYou can think about it similar to the way you think about Python indentation. It's how we define the function body / block21:00
*** scooper has quit (Ping timeout: 480 seconds)21:11
*** shmohamud has quit (Remote host closed the connection)21:13
*** shmohamud has quit (Remote host closed the connection)21:17
*** shmohamud has quit (Remote host closed the connection)21:21
*** shmohamud has quit (Ping timeout: 480 seconds)21:32

Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!