Learn how JavaScript COOKIES work! 🍪

  Рет қаралды 59,382

Bro Code

Bro Code

Күн бұрын

Пікірлер: 47
@BroCodez
@BroCodez 2 жыл бұрын
const firstText = document.querySelector("#firstText"); const lastText = document.querySelector("#lastText"); const submitBtn = document.querySelector("#submitBtn"); const cookieBtn = document.querySelector("#cookieBtn"); submitBtn.addEventListener("click", () => { setCookie("firstName", firstText.value, 365); setCookie("lastName", lastText.value, 365); }); cookieBtn.addEventListener("click", () => { firstText.value = getCookie("firstName"); lastText.value = getCookie("lastName"); }); function setCookie(name, value, daysToLive){ const date = new Date(); date.setTime(date.getTime() + (daysToLive * 24 * 60 * 60 * 1000)); let expires = "expires=" + date.toUTCString(); document.cookie = `${name}=${value}; ${expires}; path=/` } function deleteCookie(name){ setCookie(name, null, null); } function getCookie(name){ const cDecoded = decodeURIComponent(document.cookie); const cArray = cDecoded.split("; "); let result = null; cArray.forEach(element => { if(element.indexOf(name) == 0){ result = element.substring(name.length + 1) } }) return result; } Document first name: last name: submit get cookies
@ALLINONE-ko6sv
@ALLINONE-ko6sv 2 жыл бұрын
Completed the JavaScript playlist.. Thanks Bro
@chiculitamihaela8076
@chiculitamihaela8076 2 жыл бұрын
Thank you, great practical examples, I understood cookies 😍
@pexeixv
@pexeixv Жыл бұрын
Was supposed to use the js-cookie library, until I saw this video and decided to write it out myself. Well explained!
@FluoFalI
@FluoFalI Жыл бұрын
Finally i can store data within a client your a lifesaver
@ripolas
@ripolas Жыл бұрын
super underrated!!!
@kirillzlobin7135
@kirillzlobin7135 Жыл бұрын
Great tutorial. Thank you
@mrguy2
@mrguy2 Жыл бұрын
Thank you so much this tutorial was very useful and I really learned what I was doing.
@one111won
@one111won Жыл бұрын
awesome explanation!
@daniellinares4960
@daniellinares4960 6 ай бұрын
this is such a life saver, thank you!!
@mahir04
@mahir04 2 жыл бұрын
Thanks. If one day my startup makes enough money I'll pay you back for this.
@doublesushi5990
@doublesushi5990 Жыл бұрын
🤣
@chiggywiggy524
@chiggywiggy524 Жыл бұрын
We need more people like you 👏
@nischaygadher4093
@nischaygadher4093 6 ай бұрын
Awesome bro 😎👍
@hunin27
@hunin27 Жыл бұрын
Actually, you could use the browser console and go into the application sub-menu, there, cookies, local storage and session storage are displayed in a table!
@shegyoo
@shegyoo Жыл бұрын
great video
@addda1899
@addda1899 2 жыл бұрын
Thank you bro not disappointed as always, can you do a video about promises,callbacks,asyncs.. i am really struggling on those
@ytgod2094
@ytgod2094 Жыл бұрын
He already did
@coocoo3336
@coocoo3336 2 жыл бұрын
wow greate tutorial
@lucabinder9829
@lucabinder9829 2 жыл бұрын
That was complicated 🥵🥵🥵
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
Thanks!
@Ken-zh4gu
@Ken-zh4gu 10 ай бұрын
Bro thank you for your tutorials and can you please do a course in django python?.
@adityashinde7815
@adityashinde7815 10 ай бұрын
thank you so much for this valuable content bro code 🙏🙏🙏🙏🙏🙏🙏
@dmytro_kruhlyi
@dmytro_kruhlyi Жыл бұрын
Thanks for the amazing video! Where is your autocomplete? 😄
@RohitCantSing
@RohitCantSing 2 жыл бұрын
Can you plz also do fortran tutorials. I need it for my exams but I can't find someone who can explain it well like you
@iMarius977
@iMarius977 5 күн бұрын
Variables can work too?
@rudrarajkar1116
@rudrarajkar1116 2 жыл бұрын
is this what consistency is?
@Iamafuckingmadlad
@Iamafuckingmadlad 2 жыл бұрын
Yup
@TechBro4Life-uk8po
@TechBro4Life-uk8po 7 ай бұрын
Very cool my bro code. But i'd want to suggest that you replace == with === in 08:27
@Plapx3
@Plapx3 Жыл бұрын
thank bro
@fujiaaniya
@fujiaaniya Жыл бұрын
Ďakujeme za zdieľanie. Viem, že Morelogin dokáže chrániť súkromie.
@mdmahmudjamil5802
@mdmahmudjamil5802 9 ай бұрын
sir, How to overcome document.object not defined 😔
@natnaeltaye
@natnaeltaye 7 ай бұрын
i don't understand The , if(element.indexOf(name){ result = element.substring(name.length + 1); } is there anyone who can explain to me?
@hlahtunthein2830
@hlahtunthein2830 2 ай бұрын
This condition checks if the current cookie string (element) starts with the specified cookie name. indexOf(name) returns the index of the first occurrence of name in the element. If the cookie name is at the start of the string, it will return 0. This means that you are checking for a cookie that matches exactly (e.g., if name is "firstName", it will check for "firstName=value").
@nihongo_
@nihongo_ 4 ай бұрын
W bro
@Kattoe
@Kattoe 2 жыл бұрын
Is there any way to copy a specified cookie to your clipboard?
@raghabpandit2610
@raghabpandit2610 Ай бұрын
didnt understand the getCookie function can anyone pls help?
@zibozhao5789
@zibozhao5789 2 жыл бұрын
when i write document.cookie = "firstName=SpongeBob"; my cookie stays blank idk why /_ \
@abuzarn7310
@abuzarn7310 Жыл бұрын
Remove the word "Beginners" from the playList title
@TheSavageNoob
@TheSavageNoob 2 жыл бұрын
lets go
@tayaobilly8577
@tayaobilly8577 2 жыл бұрын
the video title says it all hahaha
@Vairoon
@Vairoon 2 жыл бұрын
cookies dont work, they stay blank xd
@smilekick6025
@smilekick6025 2 жыл бұрын
first comment
@hamzagohar2048
@hamzagohar2048 5 ай бұрын
This code is giving errors i copied it from the comment section to see if i made any mistakes but it still gave the same error function getCookie(name){ const cDecoded = decodeURIComponent(document.cookie); const cArray = cDecoded.split("; "); let result = null; cArray.forEach(element => { if(element.indexOf(name) == 0){ result = element.substring(name.length + 1) } }) return result; } error TypeError: Cannot read properties of undefined (reading 'length') at javaScript.js:25:39 at Array.forEach () at getCookie (javaScript.js:23:9) at javaScript.js:3:1 (anonymous) @ javaScript.js:25 getCookie @ javaScript.js:23 (anonymous) @ javaScript.js:3
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 169 М.
Build JavaScript ROCK PAPER SCISSORS in 18 minutes! 👊
18:54
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 667 М.
A game of TicTacToe written in JavaScript ⭕
18:57
Bro Code
Рет қаралды 128 М.
JavaScript Cookies vs Local Storage vs Session Storage
14:28
Web Dev Simplified
Рет қаралды 767 М.
A game of Pong written in JavaScript 🏓
24:48
Bro Code
Рет қаралды 77 М.
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
What are JavaScript PROMISES? 🤞
12:37
Bro Code
Рет қаралды 84 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 864 М.
HTML, CSS & JavaScript - How to Create a Cookie Consent Message
18:21
Web Dev Tutorials
Рет қаралды 32 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 842 М.
Learn DOM Manipulation In 18 Minutes
18:37
Web Dev Simplified
Рет қаралды 1 МЛН