YouTube2Text

Client side JavaScript day 4 part 2 — Transcript

by Negm Courses · 4,510 words · 764 segments · language en · Watch on YouTube

Full transcript

  1. 0:05What does this do, or what is it called
  2. 0:08? It adds a bit of what I create in my
  3. 0:12object. For example, if I have
  4. 0:15It should be empty. That's it. And we
  5. 0:19start by telling it here
  6. 0:24Or that's it.
  7. 0:26This will start taking the name of the
  8. 0:28object you want to apply this to. Which
  9. 0:30is the object. And then here it says you
  10. 0:32will start putting all the properties
  11. 0:34you want to define.
  12. 0:36So we said here, for example, let's put
  13. 0:37in the properties. So here is the
  14. 0:38property. And we will start here by
  15. 0:39opening the object we are passing the
  16. 0:40property into.
  17. 0:42The first thing we must add, obviously,
  18. 0:43is what?
  19. 0:44My property. Let's say, for example,
  20. 0:46Mustafa. Okay. And then we said we have
  21. 0:49one called
  22. 0:52Let's say now we make it true.
  23. 0:54And one called enumerable.
  24. 0:57And one called
  25. 1:02That's it.
  26. 1:04For instance, we will also create, say
  27. 1:12Here is the property, for example.
  28. 1:16And here is its value 26.
  29. 1:19So, we said this is responsible for the
  30. 1:21writable part.
  31. 1:23That's it. That you modify the value.
  32. 1:25I mean, if it is currently writable.
  33. 1:27I can normally, after this line, tell it
  34. 1:30here the value, for example
  35. 1:33That's it. And tell it here
  36. 1:39So, there. If we look, we will find the
  37. 1:41name is now what? Ahmed. Now, if I go
  38. 1:43here to the property and tell it, no,
  39. 1:45your property will be
  40. 1:47That's it.
  41. 1:49So that means you locked the property to
  42. 1:51the one called, so the name will remain
  43. 1:53Mustafa.
  44. 1:54You made it exactly as if you did what?
  45. 1:58You removed it because the property is
  46. 2:01already, so the name is still what?
  47. 2:04Mustafa. Alright, I went ahead and
  48. 2:06grabbed this whole name property and
  49. 2:08deleted it.
  50. 2:12So, if we look now at the user, we will
  51. 2:14find he only has age at what? At 26. Now
  52. 2:16I want to block anyone from being able
  53. 2:18to delete any property I have, so we go
  54. 2:20here to configurable and set it to what
  55. 2:21?
  56. 2:22To false or remove it. So, I just
  57. 2:25deleted the name, but the name is still
  58. 2:28what? Existing.
  59. 2:30Now, we said this is responsible for the
  60. 2:32loop, so if we came here and told it or
  61. 2:42For the user, it should now, since the
  62. 2:44property is still true, I will find that
  63. 2:47I am Looping very normally over the name
  64. 2:50and the age, but if I remove the
  65. 2:52property or set it to false, of course,
  66. 2:54here configurable is also false, we will
  67. 2:57go and find that it Showed me the age
  68. 2:59but didn't show me the name because the
  69. 3:02three values are now false for me, and
  70. 3:05likewise also Regarding the age part.
  71. 3:08Now we said we have something that does
  72. 3:10this data directly for the entire object
  73. 3:12, something called freeze and something
  74. 3:13called seal.
  75. 3:16We said freeze prevents you from—think
  76. 3:18of it as locking something—you can't add
  77. 3:20to it nor modify the contents of that
  78. 3:22thing, but you can see it.
  79. 3:24So, we are locking the configurable and
  80. 3:26locking the what?
  81. 3:29But the enumerable is still working for
  82. 3:30me normally.
  83. 3:32Seal is the exact same story but allows
  84. 3:33you to do what?
  85. 3:35Meaning it allows you to modify any
  86. 3:37value.
  87. 3:38So, these are ready-made values you use
  88. 3:40for the entire object.
  89. 3:41Okay?
  90. 3:43Did I answer your question or?
  91. 3:46>> Fine.
  92. 3:46>> Okay, does anyone need us to repeat
  93. 3:48anything else?
  94. 3:49Everything okay?
  95. 3:51Alright.
  96. 3:59What's the next topic?
  97. 4:01Okay, does anyone need me to repeat them
  98. 4:03?
  99. 4:07Where is the data stored?
  100. 4:09In the and, always.
  101. 4:14While the.
  102. 4:18Let me just double-check a few quick
  103. 4:19questions.
  104. 4:58Regardless.
  105. 5:03Or let's just settle for the first one
  106. 5:05that comes up.
  107. 5:09Or.
  108. 5:11Okay, so why?
  109. 5:13The is different, okay, the second one.
  110. 5:28Yes.
  111. 5:31Anyway, forget the third one, I have the
  112. 5:32same result.
  113. 5:44It will return the, the ones I have,
  114. 5:46right?
  115. 5:47Why?
  116. 5:49Because as we said, the first value,
  117. 5:51since you're comparing between values,
  118. 5:53it used to return because we were
  119. 5:54putting in with, so what does it return
  120. 5:56anyway?
  121. 5:59Alright, so this will return, okay,
  122. 6:01which is what? The. Okay, the third one
  123. 6:03.
  124. 6:06Or, hmm.
  125. 6:11We said with the, it always returns the
  126. 6:13first value, because if one of them is,
  127. 6:14you don't need to check the rest,
  128. 6:16because the whole term will return what
  129. 6:18?
  130. 6:20Okay, so it will return here, is there
  131. 6:22any problem with that?
  132. 6:23Okay.
  133. 6:26What?
  134. 6:28This?
  135. 6:30We said right now, the doesn't need
  136. 6:32everything to be true to return true,
  137. 6:34right?
  138. 6:35Okay, if I find any value, do I need to
  139. 6:36check the rest?
  140. 6:38I don't need to, so I return the first
  141. 6:39value.
  142. 6:41Okay, if all values are true, I need to
  143. 6:43make sure they are all true, so I return
  144. 6:45the last value, what?
  145. 6:47Okay, and the opposite with the.
  146. 6:54Alright, so thank God everything is good
  147. 6:56, does anyone need us to review it again
  148. 6:59?
  149. 7:01Hmm, everything okay?
  150. 7:04Okay, the in a regular function points
  151. 7:07to whom?
  152. 7:08And if in.
  153. 7:12It points to the, it always points to
  154. 7:15what? To the that it is inside,
  155. 7:18beautiful, okay, let's go to.
  156. 7:24Okay, why do I use this? Or what does
  157. 7:28its look like?
  158. 7:31Here we start by telling it.
  159. 7:40And here we write code, and here after.
  160. 7:44We can here.
  161. 7:48And here.
  162. 7:54Okay, so this is the way we write the,
  163. 7:57what do I use it for?
  164. 8:00Here we put code.
  165. 8:05Okay, that it returns what?
  166. 8:08Returns.
  167. 8:16>> What?
  168. 8:21In the, so if you type a word with the
  169. 8:23wrong spelling, you click here on or and
  170. 8:26you find it suggesting words for you.
  171. 8:30Okay, just so the is correct.
  172. 8:33So when I send you the code, you don't
  173. 8:34read it in two months and say, "What is
  174. 8:36this uneducated person?"
  175. 8:38and it looks bad.
  176. 8:40Okay.
  177. 8:41So here we have, in we put code so it
  178. 8:43returns. Okay. And here in the we do.
  179. 8:51Okay, my.
  180. 8:53And the here I have.
  181. 9:00Okay. Whether in.
  182. 9:03The case of, okay, it's done.
  183. 9:10Whether my code had an error or what?
  184. 9:13So this is exactly the code of what
  185. 9:15happens. Okay. Okay, now we will take it
  186. 9:18as a concept. So later, God willing,
  187. 9:20when we talk about the part of.
  188. 9:22Or that we are done, you will find that
  189. 9:25we start using something called.
  190. 9:28This might return or might not.
  191. 9:31Okay, so for the shape of this, we start
  192. 9:32using.
  193. 9:34Okay, let's take an example.
  194. 9:36If I came here, for example, and told it
  195. 9:38.
  196. 9:41equals 20, for example, okay, and I came
  197. 9:42here and did the.
  198. 9:47I came here and told it, if this value
  199. 9:50is greater than 30, okay.
  200. 9:58And here, let's write for example, is
  201. 10:01there any problem?
  202. 10:04So now I am telling it if this value is
  203. 10:07greater than 30, okay, start by
  204. 10:09triggering this error, right?
  205. 10:11What if I make it 40?
  206. 10:16So now, what is it supposed to do?
  207. 10:19And the fact that it did that means the
  208. 10:21part of the code after it, what?
  209. 10:23Will not be executed, right? Well, let's
  210. 10:25see for example, let's say the word.
  211. 10:29I looked and found that it printed what
  212. 10:31?
  213. 10:32The word normally, there was no output
  214. 10:34at all, why? Because we said we have
  215. 10:36here, I put any code to be outputted.
  216. 10:40And here is the form of the error, did
  217. 10:42we write anything about the error form?
  218. 10:45No. You can format the error the way you
  219. 10:47like. You want to output it in an alert
  220. 10:49, you want to output it in a tag, you
  221. 10:50want to print it in the console.
  222. 10:52All this is done through whom?
  223. 10:54The error, let's take it one by one,
  224. 10:57here is the error, this error parameter
  225. 10:59captures what?
  226. 11:01The error above, or we can dispense with
  227. 11:03it entirely and start writing the error
  228. 11:05we started here.
  229. 11:07Okay, let's write it as we started here
  230. 11:08, alright? However, because we are using
  231. 11:10a ready-made one, or it's coming from
  232. 11:12outside, it's always better to use what
  233. 11:14?
  234. 11:15The error of the response, as we can see
  235. 11:17it outputted the error and sent the word
  236. 11:19test after it, it didn't stop what?
  237. 11:21The flow of the code. So let's try to
  238. 11:24output it in another way, let's say here
  239. 11:26.
  240. 11:32So it also outputted it in the form of
  241. 11:33what?
  242. 11:35But it still didn't stop the code flow
  243. 11:37because if it stopped the code flow,
  244. 11:39anything below it wouldn't be executed,
  245. 11:41right?
  246. 11:43Well, I want to print it in the console
  247. 11:45, here.
  248. 11:48Currently, God willing, on Sunday we
  249. 11:49will start to dispense with all this and
  250. 11:51we will say here.
  251. 11:55For example, and here we start to
  252. 11:57display what? Our error.
  253. 12:06Okay, and here is the error, and we can
  254. 12:08start saying here.
  255. 12:13Here we must put the code because I used
  256. 12:16it, and I will say here.
  257. 12:20Alright.
  258. 12:22My error on the page, but if I don't
  259. 12:25want to output the word error, we said
  260. 12:28what was my error called?
  261. 12:31The message, exactly. Okay. So here
  262. 12:33instead of displaying the whole error. I
  263. 12:35can say show me only the message here.
  264. 12:40Okay. So it showed me just the message
  265. 12:42you wrote inside the error.
  266. 12:45So the error block puts any code that it
  267. 12:48outputs.
  268. 12:49Okay. The error handles the error format
  269. 12:51in the way that suits you. And it
  270. 12:52doesn't stop the code flow. The code is
  271. 12:55executed in both cases. Okay. Here.
  272. 12:58Okay, whether there is an error or not.
  273. 13:00Okay. Here is the error, for example.
  274. 13:05Okay. Let's make this 20, so it won't
  275. 13:07throw any error.
  276. 13:09Alright. So it didn't even enter the
  277. 13:11error phase. Because I didn't have any
  278. 13:12error or problem. It printed what is
  279. 13:14found where?
  280. 13:16And the code that we had already written
  281. 13:18outside the block, so any code that
  282. 13:21might throw or is suspected of throwing
  283. 13:23, we always handle it how?
  284. 13:27To ensure that I don't stop the flow of
  285. 13:29the code being executed.
  286. 13:31That's it.
  287. 13:32Of course, the process seems easy now.
  288. 13:34But when we start taking APIs and start
  289. 13:36fetching data from the API.
  290. 13:37God knows whether this data will return
  291. 13:39valid or have issues. Right. So we will
  292. 13:42start using what?
  293. 13:44Right.
  294. 13:47Beautiful.
  295. 13:50>> Oh engineer.
  296. 13:52>> It's possible, yes, in the beginning I
  297. 13:54didn't use it, I only did the catch
  298. 13:56block at first.
  299. 13:57>> I mean.
  300. 14:00>> Good, good.
  301. 14:02When we deal with the backend, for
  302. 14:04example, dealing with the DB, so now I
  303. 14:06want to perform a query.
  304. 14:10I might enter the parameters incorrectly
  305. 14:12, so it will throw what?
  306. 14:14The database error.
  307. 14:16Okay, if I get an error, I want to close
  308. 14:18the connection with the server, or at
  309. 14:21some point, I want to execute code
  310. 14:23whether it worked or what?
  311. 14:25Or didn't work. In both cases, close it
  312. 14:27for me. In Angular, we take something
  313. 14:29called a connection that stays open
  314. 14:31between us. Once I've fetched my data,
  315. 14:33do I need the connection to stay open?
  316. 14:36No, so where do I close it? In the
  317. 14:38finally block.
  318. 14:42Okay, we finished try-catch; let's start
  319. 14:44talking about callback functions.
  320. 14:51What is the idea of a callback function
  321. 14:52? Let's create a function, let's call it
  322. 14:55, for example.
  323. 14:59Calculation.
  324. 15:02This won't take the logic from me, for
  325. 15:04example, we want to perform an operation
  326. 15:06, so I need to pass it the operation I
  327. 15:08will execute, right?
  328. 15:10And the numbers I will do what with?
  329. 15:14The operation, let's settle for two
  330. 15:15numbers, here is the callback, and here
  331. 15:17are X and Y that we will perform the
  332. 15:19operation on.
  333. 15:22And here in my return, I will hold the
  334. 15:24result of executing the operation.
  335. 15:28The result of the operation, here it is
  336. 15:30.
  337. 15:32So now it will receive the operation and
  338. 15:35receive the two numbers I'll work with,
  339. 15:38and its return will be the return of who
  340. 15:40?
  341. 15:43The operation.
  342. 15:49So, if I have.
  343. 15:54Receive from me here, for example, and
  344. 15:54here.
  345. 15:56The operation.
  346. 15:58And here is.
  347. 16:05Here.
  348. 16:07And here.
  349. 16:15Here.
  350. 16:17That's it.
  351. 16:23And here is, for example, if the
  352. 16:25operation is greater than, so it doesn't
  353. 16:28give me an error.
  354. 16:31Here, what about?
  355. 16:33Is there any problem with that?
  356. 16:36Well, let's assume the function is in
  357. 16:38another file; it's not with me now, and
  358. 16:40I can't call it directly.
  359. 16:42All my calls will be through whom?
  360. 16:47This one, which is the only one that can
  361. 16:50execute it. So if I come here and tell
  362. 16:52it.
  363. 16:55It's waiting for what from me?
  364. 16:58My operation that I will execute, and
  365. 17:00then the numbers you will execute it on
  366. 17:02.
  367. 17:03Let's send it the addition, for example
  368. 17:05, and the two numbers, say five and ten
  369. 17:07. Let's see, it executed how much?
  370. 17:1015. Okay, the same function, I went and
  371. 17:13passed it here.
  372. 17:17So it will start subtracting the two
  373. 17:18numbers, the same.
  374. 17:22Who is the only one that can call this?
  375. 17:26The calculation function.
  376. 17:29And all this, who is the only one that
  377. 17:31can execute it?
  378. 17:33The function itself is the only one in
  379. 17:35control of the execution of the
  380. 17:37operation.
  381. 17:39Alright, so this is the same thing we
  382. 17:41covered, remember, from yesterday?
  383. 17:56And here we told it okay.
  384. 18:01And we go up and start telling it.
  385. 18:07Okay, when I was sending directly, we
  386. 18:08said that it was what?
  387. 18:10Executing them, right, in what order?
  388. 18:13Exactly, but here we were passing
  389. 18:15something called the, which is
  390. 18:17considered for me what?
  391. 18:20Okay, if we did the of the.
  392. 18:30Okay, and here it has the A and the B
  393. 18:33and here we tell it the A minus the B,
  394. 18:36and I came here to the and went.
  395. 18:42Isn't this the exact same structure we
  396. 18:44just made above, right?
  397. 18:46So that is what?
  398. 18:48Who performs this?
  399. 18:51Who?
  400. 18:53It is what controls its, okay, I don't
  401. 18:56do it, who performs the for it, who?
  402. 19:00Okay, so consequently, it will start
  403. 19:02sorting the for me in ascending order,
  404. 19:03and if you want it descending, you
  405. 19:05reverse the?
  406. 19:08The, okay, so let's assume that I have
  407. 19:10is what, just a second, but I don't know
  408. 19:13the, so let's take an example, we will
  409. 19:15take something called.
  410. 19:21Here we have it has something called, we
  411. 19:23are dealing with for the first time in
  412. 19:25our lives, right?
  413. 19:27Okay, so the here takes from me.
  414. 19:31Right? Okay, I will perform the for it
  415. 19:32here.
  416. 19:38I will perform the here and not look at
  417. 19:40any, and let's assume we don't know the
  418. 19:42, I want to know the that I am receiving
  419. 19:45, it's who?
  420. 19:49In any, I want to know what the that is
  421. 19:50coming to me is, who?
  422. 19:53The, exactly, so here we will start with
  423. 19:55who?
  424. 19:57To see what this does and who the that
  425. 20:00it receives is, right?
  426. 20:02Okay, let's take a look, but let's just
  427. 20:05make the numbers a bit smaller so the
  428. 20:07process isn't too huge, let's say three
  429. 20:10numbers, we found that it printed my for
  430. 20:12me how many times?
  431. 20:15Three times, meaning it prints the with
  432. 20:17every what? With every number, right?
  433. 20:20Every number it prints with my.
  434. 20:25I looked at the, I found it receives
  435. 20:26from me how many?
  436. 20:27Or how many, I mean? Three, right? The
  437. 20:29first is the one, the second thing is
  438. 20:32its in the which is zero, and then my
  439. 20:34full.
  440. 20:35Okay, let's go to the second, we found
  441. 20:38the second which is two, and its is one
  442. 20:40, and then the full.
  443. 20:43The third, the which is four, its is two
  444. 20:46in the, and here is the, so the inside
  445. 20:49this receives from me how many?
  446. 20:53Three, the and the and the, right? Okay
  447. 20:57, let's verify. Let's go here to the
  448. 21:00just.
  449. 21:01We found it printed how many?
  450. 21:03One, two, and four. Okay, I did here to
  451. 21:06the.
  452. 21:09I will find what? Zero, one, two.
  453. 21:11I did, it will print my what for me?
  454. 21:14Three times. Okay?
  455. 21:16So you can, any, inside, okay. And know
  456. 21:20what the that you are passing to the is
  457. 21:22.
  458. 21:23Okay, I have this, I use it to execute a
  459. 21:26specific on the.
  460. 21:28Meaning, for example, if I want to
  461. 21:29perform a, I can do it with the.
  462. 21:31You don't need to create a and define a
  463. 21:33variable called. And start telling it i
  464. 21:36is smaller than the and so on. We can
  465. 21:39tell it here.
  466. 21:42Two empty and directly here in the one I
  467. 21:44know is on all the existing ones, let's
  468. 21:47start telling it
  469. 21:50Who?
  470. 21:52For or for directly.
  471. 21:55Isn't this the one that grabs it with
  472. 21:57every loop, is that right? So it starts
  473. 21:58entering what for me?
  474. 22:00My directly. Any problem?
  475. 22:03Does anyone have a question?
  476. 22:05Okay, what else can we use it for?
  477. 22:09Ah, we haven't taken the yet, no, leave
  478. 22:11that for when we go to the for what?
  479. 22:14To see the shape of the directly. Done?
  480. 22:16The we have can be used for any you want
  481. 22:19to apply to the, well let's ask an
  482. 22:22important question, what is the of this
  483. 22:25? Didn't we take any and know its?
  484. 22:28Let's ask quickly, what was its?
  485. 22:32>> Which is the
  486. 22:34>> Which is the new, okay, the
  487. 22:38>> The that I removed, well done, the
  488. 22:48>> The that was removed
  489. 22:54What do they return in?
  490. 22:56In exactly, well done, great.
  491. 22:58What else from what we took?
  492. 23:06The
  493. 23:15>> The new, the new, that's right? Okay.
  494. 23:18And the
  495. 23:21>> The new that I merged together. Well
  496. 23:24done. Great. That's it. The we have, and
  497. 23:27this question I mean, I will ask it now
  498. 23:29, I will ask it in the exam, and I will
  499. 23:32ask it in the, done. There, I told you.
  500. 23:35Okay.
  501. 23:37If I came and did for the whole, and
  502. 23:39came and did for this, done.
  503. 23:42I will find that it returns
  504. 23:45The of it always.
  505. 23:48That's it, the situation is done. Even
  506. 23:51if we did it ourselves. Meaning if I
  507. 23:54went inside and did, for example, the
  508. 23:56word ah. I will still find that its is
  509. 23:59what?
  510. 24:02So always my has its done
  511. 24:06What?
  512. 24:09Exactly, it has no, because I will have
  513. 24:11another that returns for me, for example
  514. 24:13, like the filter and, when we take them
  515. 24:16in the, God willing, these return, but
  516. 24:18does not return anything, it executes a
  517. 24:21specific and that's it.
  518. 24:23Done, just like the, the grabs something
  519. 24:26from the, it executes a specific and
  520. 24:29that's it, okay?
  521. 24:30Is there any problem with that?
  522. 24:33So the callback, guys, I use it because
  523. 24:35there is another that does its or
  524. 24:37executes its, you just pass it and it
  525. 24:39what?
  526. 24:40It works. It runs.
  527. 24:45We still have another session with the
  528. 24:47callback tomorrow, God willing, in the
  529. 24:49when we take something called the, done
  530. 24:51.
  531. 24:53Like click for example, when you do a
  532. 24:54click, you'll find that we pass it and
  533. 24:56it's the one that executes the, when
  534. 24:57does it execute it?
  535. 24:59When the click, and so on.
  536. 25:01Done?
  537. 25:02Does anyone have any questions regarding
  538. 25:03the part of the
  539. 25:06Is everything okay?
  540. 25:08Beautiful.
  541. 25:14So we have the left.
  542. 25:17We finished very early.
  543. 25:20Let's talk now about
  544. 25:27The came to you, man, you're welcome.
  545. 25:31The we have, guys, is one of the very
  546. 25:33important things in JavaScript that
  547. 25:35clarifies many things, for example, you
  548. 25:37guys, did anyone take
  549. 25:41Has anyone studied before? You know the
  550. 25:43, right?
  551. 25:47You know why the retains the value?
  552. 25:52So, you’re supposed to, when you change
  553. 25:55anything in the code, it re-executes
  554. 25:57everything from the start.
  555. 26:00So why does it keep the old value?
  556. 26:03Because of the closures, okay?
  557. 26:05Now, let's look at what our code
  558. 26:07consists of; let’s say we have this, for
  559. 26:09example, let's call it...
  560. 26:12It’s not difficult, by the way.
  561. 26:14Alright?
  562. 26:19Here is the scope of this one, let's say
  563. 26:22we put a variable here, and here we have
  564. 26:24another function.
  565. 26:30Okay, and this second function...
  566. 26:39Right, this is exactly what it looks
  567. 26:41like. Let's do this, when we were
  568. 26:44talking about...
  569. 26:47We said who sees whom?
  570. 26:52The inner one sees the outer one, but
  571. 26:54the outer one doesn't see the inner one
  572. 26:56. So, can I do this in this case?
  573. 27:00In this part?
  574. 27:02Exactly, the inner function or the inner
  575. 27:05scope can easily see the outer one. Very
  576. 27:08good. So here, if I said...
  577. 27:13Okay, if I do this, what will it hold?
  578. 27:26It holds...we said as long as I hold
  579. 27:29this, I am holding...
  580. 27:33What is the returned function exactly?
  581. 27:36Still, okay? Because I feel like you
  582. 27:38don't believe me, even though I'm not
  583. 27:41lying. Here it is, okay. Now I want to
  584. 27:43execute this, what do I have to do?
  585. 27:47Run it, right? So in this case, what
  586. 27:49will it hold?
  587. 27:51Zero or one?
  588. 27:53It will hold zero, okay. So here is zero
  589. 27:56. Now if I did...
  590. 28:05One. You are holding this, which is what
  591. 28:07executes it, right? When does it reset
  592. 28:10to zero? When I run...
  593. 28:12So it starts to redefine the variable to
  594. 28:14what? To zero. That’s the trick right
  595. 28:16there, we’ll get to that later, okay? So
  596. 28:18here is...One, okay. And every time you
  597. 28:21increment, it will start incrementing
  598. 28:24your...Okay, good. I came here and told
  599. 28:26it...
  600. 28:32Okay, and I did here...
  601. 28:37What will it print?
  602. 28:44What? What’s your explanation, then?
  603. 29:01Are you recording me, man? Take it and
  604. 29:03I'll send it to you, and besides, you
  605. 29:05have the code.
  606. 29:09Okay.
  607. 29:13The one that was five, the incoming
  608. 29:15value should be five.
  609. 29:16Are we saying it will start from zero or
  610. 29:17keep it as five?
  611. 29:21Nice. Okay, very good.
  612. 29:23Nice, nice.
  613. 29:24Okay, okay, okay, sure.
  614. 29:27Normally, as long as I ran this, it
  615. 29:28should start executing this from the
  616. 29:30very beginning, right?
  617. 29:32So as long as we execute from the
  618. 29:33beginning, what will it do to the value
  619. 29:35? It will reset it, right? Okay.
  620. 29:37Let's remember something.
  621. 29:39Or...
  622. 29:42Did I, did I change its source or its
  623. 29:45reference?
  624. 29:48I didn't change its reference, right?
  625. 29:50So, this is holding what?
  626. 29:54Different from whose reference?
  627. 29:57So, it will continue very normally and
  628. 29:59output what?
  629. 30:00Five. When will it print zero?
  630. 30:10If I did...
  631. 30:13Because now I am...The old one that I
  632. 30:15was holding for the function, I removed
  633. 30:17it and brought a new one with what?
  634. 30:19Outer...does that mean I...Reset it and
  635. 30:21I’ll start again from...From the very
  636. 30:23beginning, okay?
  637. 30:25So here we have...Zeroing my value, okay
  638. 30:28? So when something like hooks comes
  639. 30:30along, it is in this exact form, it
  640. 30:32keeps the value no matter what you do,
  641. 30:35the original value inside is still...
  642. 30:37Preserved because the component function
  643. 30:39didn't get...From the very beginning.
  644. 30:41Okay, it is preserved by something
  645. 30:43called the file.
  646. 30:44We've been hearing these stories, and
  647. 30:45until we get to it, we actually have
  648. 30:47something in Angular called Signals,
  649. 30:48which is similar to what? useState,
  650. 30:50right.
  651. 30:52So, as long as you haven't changed the
  652. 30:54reference of the main function, or
  653. 30:55changed its calling, the closure will
  654. 30:57keep going with me, right?
  655. 31:00In the closure part. Now, let's start
  656. 31:02our debugger.
  657. 31:04To see it step-by-step and observe the
  658. 31:07closure's scope.
  659. 31:10Alright, the debugger is running. What's
  660. 31:13in my scope right now?
  661. 31:15The global scope. We'll go down a line,
  662. 31:17fine. It will start entering the outer
  663. 31:20function, and now the outer function's
  664. 31:22local scope is there. The 'this' points
  665. 31:25to the window, and the count value is
  666. 31:27currently what?
  667. 31:29It's undefined. Why is it undefined? We
  668. 31:31are here, guys.
  669. 31:33Why is the count value currently
  670. 31:34undefined on this line?
  671. 31:37Because of what?
  672. 31:45No, not that.
  673. 31:48Yes, why then? I mean, before the line
  674. 31:50executes, why do I know the value of
  675. 31:52count is undefined? What is that term?
  676. 31:55What is the name of that term we
  677. 31:57mentioned? Hoisting, exactly, because of
  678. 32:00what? Hoisting, right. So, we've done
  679. 32:02the declaration, now we'll start giving
  680. 32:04it its initial value, which is what?
  681. 32:06Zero, right. Now, as we can see, the
  682. 32:08local scope has also captured the return
  683. 32:10, which is, for me, what? My function.
  684. 32:12We went to the next line, it's starting
  685. 32:14to call the result, it's bringing up
  686. 32:16whom?
  687. 32:19The closure, right. The closure is
  688. 32:20coming from whom? From the outer, and it
  689. 32:22currently holds the count value of what
  690. 32:23?
  691. 32:24Zero. Now we start increasing our count
  692. 32:27by one. It goes to execute the next
  693. 32:30function. Our closure's value is
  694. 32:32currently one.
  695. 32:34It executes count ++, so its value
  696. 32:36becomes two, and so on, infinitely,
  697. 32:38until we reach the point where it's
  698. 32:40finished.
  699. 32:43As soon as we finish this line, we go
  700. 32:44back to the result, and we return to
  701. 32:46what? The beginning.
  702. 32:48As soon as we execute it, it will go
  703. 32:49back to the start and set the count back
  704. 32:51to what?
  705. 32:53Currently zero. Then, the next line
  706. 32:55makes it one.
  707. 32:57Then it will go and do the result for
  708. 32:58you from the very beginning, and you'll
  709. 33:00find the count here is zero, and the
  710. 33:02next line you'll find it's what?
  711. 33:05One. So, as long as you haven't changed
  712. 33:08the reference of the one you're holding
  713. 33:10, the count will continue normally.
  714. 33:12As soon as you change the reference, it
  715. 33:15will start to what?
  716. 33:16Reset and restart. Your result from the
  717. 33:18very beginning.
  718. 33:20Is there any problem with that?
  719. 33:22Does anyone have any questions?
  720. 33:25Okay, so the reason it continued after
  721. 33:28four and printed five here is that I,
  722. 33:31even while doing the process, didn't
  723. 33:33change what?
  724. 33:35The reference of the variable. Of whom?
  725. 33:37Of the function. You're calling it
  726. 33:39inside. Is there any problem with that?
  727. 33:43Is everything clear so far?
  728. 33:44Does anyone have any questions?
  729. 33:47Does anyone need us to repeat anything?
  730. 33:49Alright, looks great.
  731. 33:55So, we've finished, or covered most of
  732. 33:57the basics. Of course, there are other
  733. 34:00things, but we'll talk about them as we
  734. 34:02go along, like the...
  735. 34:05And all these things, they are there,
  736. 34:07but we'll talk about them in the context
  737. 34:09of our work.
  738. 34:11Tomorrow, or Sunday, God willing, we
  739. 34:14will start talking about and dealing
  740. 34:16with the things inside the [code]. When
  741. 34:19we were explaining the first day of the
  742. 34:22[course], we said that we could perform
  743. 34:25[operations] or [modifications] to the [
  744. 34:28code]. So here, we will be forced to
  745. 34:30place our [code] where?
  746. 34:33Before the [code] closure, or it might
  747. 34:34be at the top, and I use a specific [
  748. 34:35tool] with it called [name], which we
  749. 34:37will talk about in detail tomorrow.
  750. 34:38We will start taking the [code],
  751. 34:40modifying what’s inside it, removing,
  752. 34:42adding—all of this, God willing, we will
  753. 34:43do tomorrow. All right? And we will have
  754. 34:46Tuesday left to talk about something
  755. 34:48called [the topic]. There are also some
  756. 34:50things related to the [code] itself that
  757. 34:52we will need to learn along with the [
  758. 34:54topic].
  759. 34:56And so on. All right?
  760. 34:58Does anyone have any questions?
  761. 35:00Is everything okay?
  762. 35:02Okay, let's look at the [assignment].
  763. 35:07Only two tasks today, that's it. Let's
  764. 35:09just finish the [code].

About this transcript

This page contains the full transcript of Client side JavaScript day 4 part 2 by Negm Courses, generated from the public captions YouTube serves with the video. The transcript has 4,510 words across 764 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.