Primitive vs Reference - What's the difference - JavaScript Bangla ( বাংলা ) Tutorial
HTML-код
- Опубликовано: 13 июл 2024
- In JavaScript, a variable may store two types of values: primitive and reference. JavaScript provides six primitive types as undefined, null, boolean, number, string and symbol and one reference type called object. In this tutorial, you will learn the differences between primitive and reference values. While doing so, you will also learn some fundamental concepts such as memory allocation in stack and heap, master object, wrapper primitive types and function parameter pass by reference. You will also understand how to copy sensitive reference values immutably which will help you working with state management in popular JavaScript libraries like React, Vue etc.
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
0:00 - Intro
1:19 - Simple Example
4:40 - Understanding the Concept visually
16:45 - Mutation vs Assignment with example
19:54 - Copy References immutably
22:46 - Copy nested References immutably
29:33 - Primitive Wrapper Type
34:24 - Primitives are not mutable
35:52 - Pass by Reference / Value
42:28 - Conclusion
Reference:
1. JavaScript Prototype - • Prototype - the founda...
2. Spread Operator - • #17 - Spread Operator ...
3. JavaScript Scope - • JavaScript Scopes - th...
4. lodash - lodash.com/
#primitive_reference #javascript #bangla_programming_tutorial
Most underrated bangla programming content
এই প্রথম কোন বাংলা চ্যানেল এর প্রতিটা ভিডিও খুজে খুজে দেখতেসি। অসাধারন ভাই. চালিয়ে যান।
❤️
I was exactly looking for this.
Lodash was the thing that I was looking for 3 days.
Thank you for this video.
Your ability to explain is amazing. Thank you very much.
vaia you are awesome ........ so many many thanks
আপনার সব টিউটোরিয়াল সেরা স্যার।আপনি আগা গোড়া সব বিষয় গুলো explain করেন।আমার দেখা মতে বাংলাতে এমন কোন টিউটোরিয়াল নেই যে আপনার মতো এতো detail বুঝিয়ে দেয়। আপনি প্রোগ্রামিংকে আমাদের মাঝে অনেক আলাদাভাবে প্রকাশ করেছেন।প্রোগ্রামিংয়ের boringness কাটিয়ে তুলে প্রোগ্রামিংকে ভালোবাসতে শিখিয়েছেন।
কে কি বলে জানিনা তবে আপনি সত্যি প্রোগ্রামিং বা জাভাস্ক্রিপ্ট এর বস।ঠিক আপনি যেভাবে নিজে বোঝেন ঠিক সেই ভাবেই নিজের বুঝ মানুষের কাছে প্রকাশ করেন।যা সবাই পারেনা।
ভালোবাসা নিবেন প্রিয় স্যার ❣️🥰😍❣️💞💕💞
ভালবাসা থাকলো।
@@LearnwithSumit ❤️❤️
Best Video on RUclips about this topic take Love Sir 💙
super informative.. amazing teaching skill, everything is crystal clear
খুবই গুরুত্বপূর্ণ এবং তথ্যবহুল একটি ভিডিও। ধন্যবাদ আপনাকে সুমিত স্যার।
sir thank you for your this type concept
vaia bolte gele osadaron video. Ami apnar w3school JS course ta follow korsi . Shike onek moja pacci. Thank you , ato sundor akta course ar jonno
great vai ...your explanation masaallah
well explained vai...keep going forward
Nice video keep it up bro
onek kisu clear holo Thanks
Thank you very much... amra insaallah apnar student hisabe apnake gorbito korbo.. insallah onek valo kisu kore dekabo world a .. sob credit apnar e hobe sedin .. keno na amader hate khori apnar moto mohan ekjoner hate hosse.. je free tei amader full direction dia bindu bindu kore ghore tulse
Learned a lot of things dada
Awesome explanation.
অনেক ভিডিও দেখে এই বিষয়ে ক্লিয়ার হইনি।
অবশেষে আপনার ভিডিও দেখে পানির মতন ক্লিয়ার হয়ে গেলাম
ভাই, আপনাকে অসংখ্য ধন্যবাদ।
So good, so Informative
wow, just amazing
vaia you are awesome :) international standard er video .. thank you
Amazing Explanation. 😍
Amazing explanation. 💖💖
excellent video vaiya
Thanks a lot. Bhaiya
Nice presentation.
Sir, Thank you.
সুন্দর!
Excellent!
Keep continue good jobs
Awesome
It's really the best tutorial for javascript lovers. Love you, sir.
take love
Just woow, vy
Another masterpiece
Thanks a lot. Please stay tuned.
amazing teaching skill, everything is crystal clear
Thanks. Please subscribe if you find this video useful and take a look at other videos in this channel.
Great
😯😮 super informative..
Thanks. Please share as much as you can if you like these contents.
Primitives' and reference er importance ta bujhlam. age ato important mone kortam na. Thanks Bhaiya. :-)
this is one of the most important knowledge you need at first in any programming language and this is important for data structure as well
thanks brother for this beautiful tutoria l.I am beginner in java script ..all of your tutorial help me lot.I am so much greatfull to you.
i feel honored. stay tuned
A very useful topic to understand? thnx bro. if u would make these tutorials a year ago it could save me a lot of time
Thanks bro
you are specially blessing for non-CSE student 💙🤍💙.
Thanks 😍
thanks
Bro, you are doing great!!
Thanks bro
Sir , Difference between Stack and Heap memory in javascript , এই সম্পর্কে একটা টিউটোরিয়াল দিবেন প্লিজ
Excellent explanation!!!
thanks
দাদা আপনার ভিডিও দেখে অনেক অনেক উপকৃত হয়েছি। অনেক কিছু শিখেছি। আরকেটা আবদার কী করতে পারি? জাভাস্ক্রিপ্ট অবজেক্ট অরিয়েন্টেড প্রোগ্রামিং নিয়ে একটা প্লে লিস্ট ?
Thanks a lot summit bhai onek kiso jante parlam.
By the way, Nested reference array of object or array deep copy korar jonne library (lodash) use na kore, khub e simple akta syntax use kore korte paren.
let original_value = [
{name : 'Sakib',avg_sroces : { one_day : 85,t_20 : 65}},
{name : 'Tamim',avg_sroces : { one_day : 75,t_20 : 70}},
]
let new_value = JSON.parse(JSON.stringify(original_value))
it has too manu drawbacks! it’s slow and most importantly if you have functions and special type of objects inside an object, they lost their functionality
আমার দ্বারা সম্ভব হলে কয়েক billion likes দিতাম👍👍
why not JSON.parse(JSON.stringify(object)) instead of lodash?
23:14 vaiia ami boltesilam Angular likhben thik tokhn e apni bollen "Angular ami likhbo na , karon eta library na" :P
You r great brother and kind enough
Our creator Almighty Allah bless u
❤️❤️❤️
amazing content
Thanks vai
❤️❤️❤️
ভাইরে আপনার টিউটোরিয়ালগুলো কতটা সেরা হচ্ছে বলে বোঝাতে পারবনা। প্রিমিয়াম কোর্সগুলোও এভাবে বোঝায়না। ❤️❤️❤️
ধন্যবাদ ভাই। subscribe করতে ভুলোনা।
@@LearnwithSumit অনেক আগেই করে রেখেছি।😍
🤟🤟🤟Supper 🤟🤟🤟😍😍😍
দাদা, সুধু কলব্যাক নিয়ে একটা টিউটোরিয়াল দিবেন প্লিজ।
will do
rocket informative
viya tana 20 days ami apnar javascript playlist gulo ses koray asci alhumdulillah bujtaci ami dinay 8-10 houre somoy discci bortomanay ami ai playlist a assi apni ja dakhiya dissan sob kortay partaci kinto kisu din por ar mathay thaka na jokhon abar video dhaki thokhon abar monay poray biginer hissabay ami ai playlist ses korar por ki korbo apnar video gula dakhar por sathay sathay 1-2 bar practic kori
ami java script kay valo vassay falci vai
sir stack er video link ta ki dewa zabe eta khuje pacchina ba pele o bujhtechina
Stack somporke kon video te bola hoyeche bhai ...
primitive value pass by reference hoy?
awesome..
but vscode e ki font use koren eta ektu bolen.
Fira Code (Free) and Operator Mono (Paid)
🥰🥰🥰🥰🥰
❤❤❤❤❤
Thanks. Please subscribe and stay tuned
দারুন
ভাইয়া, JavaScript Iterators নিয়ে যদি একটা ভিডিও দিতেন, উপকার হইতো.
Accha debo vai.
Dada akta question oi object deeply copy korar time e lodash na use kore jodi JSON.parse(JSON.stringify()) use kori tale tar ki kono disadvantage ache??
disadvantage nai. tobe ektu boro object hole ei technique ta slow
Behind the scene, array/object passes its value as pointer. A C programmer can feel this low level concept very easily.
Vaia, deeply copy javascript এর মাধ্যমে কীভাবে করব?lodash use না করে। বললে খুবই উপকৃত হতাম। please
24:47 nothing to say, Man!!! (At this time I could not but laugh)
Sorry to ask a silly question.
Kono library jodi ami cdn use kore amar html file e add kori, kon variable use kore ami library take access korte hobe eta kivabe bujha somvob? or kono vabe ki change kora somvob?
i.e. lodash er khetre _ use kore library access korte hoy. I think this is the default behavior. kintu eta ki kono vabe change kora somvob?
ha obossoi change kora somvob but not recommended. jQuery er $ sign er collision atkate kintu amra onek samay e setake change kortam. ar lodash othoba onno jekono library er konta kivabe kaj kore, eta bujhte hole tader corresponding documentation porte hobe. sekhanei sob instruction deya ache.
Vai react or node nea course start koren
Will do
❤❤❤ 02 Dec, 2023
Javascript is always "pass by value".
The thing is, the value that is passed is always a memory address.
Reference and Memory Address are not the same thing!
Reference is the alias of the variable. Reference is a way to refer a variable by different name. Its not different entity.
Memory Address/Pointer on the other hand is a separate variable which contains the memory addrsss. Thats why if you reassign memeory address its does not affect the main object. But If you modify object by the memory address then it affects the original object.
If you know some C++, it supports pass by value, reference,pointer all.
void pass_by_pointer(int *a) {
*a = 3; // mutates a
int b = 1;
a = &b; // reassign a to address of b
*a = 11;// this now changes b
}
void pass_by_ref(int &a) {
a = 3; // this changes a itself, this is not ressign
}
in summary, JS is always pass by pointer value. Pass by reference is a different thing.
I don't think so, there is no thing named passed by pointer. Pointer carries the pointed memory address, you can still receive memory address without a pointer in function parameter. When you pass array in C, it just passes the address of the first element, rest of the array is calculated by this formula: base_address + (index*sizeof data_type)
And obviously reference is same as memory address. Pass by reference means passing out the memory address which will received by a pointer. In C, you can use both syntax, int arr[ ] or int *arr, both will do the same thing.
@@md.redwanhossain8822 I completely agree with you. Everything depends on the defecation of Pointer, Reference.
In js, java, python... pointer and reference are used interchangeable. If your definition of pointer and reference is same then all your comment is 100% valid.
But in C++ reference and pointers are two completely different things. Reference is nothing but an alias for the object. In that case Pass by Value, Pass by Reference has completely different meaning.
The point I am trying to make is this,
if you considered "Java/Js/Python.. is always Pass by Value of the address" which I said as "pass by pointer" (I know it is not widely used terminology) then every behaviour makes sense!
Other wise,
function foo(a) {
a = 5;
}
seems like, I am changing a. but the change is not reflected outside. If you mentally think "this is pass by address" (or in my term, pass by pointer) it makes sense. a = 5, changes the address but a.val = 5 changes the val property pointed by a.
@@moazmahmud4285 I explained in terms of C, I need to explore more about C++
আমি আগে অবজেক্ট কপি করতে
var b = JSON.parse(JSON.stringify(a));
এই মেথড ইউজ করতাম। আপনার মন্তব্য জানতে চাই এটি নিয়ে। এর কোনো ডাউনসাইড আছে কি?
Very advanced question. Thanks for asking. Technically, yes, it has some downsides and it's not recommended. It's a very old style of copying objects.
first, it's unpredictable
JSON.stringify({ key: undefined }); // u will get "{}"
JSON.stringify({ key: function(){} }); // u will get same "{}"
it will behave unpredictably in case of "ES6 Symbols()" also.
here's another type of issue:
JSON.stringify({ key: Nan }); // u will get "{"key": null}"
JSON.stringify({ key: Infinity }); // "{"key": null}"
Finally, u will face problem with the Date(). Dates will be parsed as Strings, not as Dates. So, if you store Dates object and clone using JSON, you will lose them, too.
finally, it's not quick as lodash cloneDeep, jQuery or even ur own deep cloning using recursion. Always try to avoid JSON.stringify as much as possible.
@@LearnwithSumit thanks vai 😍 for such detail explanation. I will go with lodash
>>> @@LearnwithSumit wow. আমার মাথায় একই প্রশ্ন ঘুরছিল এই ট্রিকটা থাকতে কী জন্য lodash ব্যবহার করবো? এখন সম্পর্ন্ন clear হয়ে গেছে। Thank you very very so much:)
another diamond
:-)
যখন function এর ভিতর object দিলেন সেটা passByReference এর কারণে বাহিরে ও চেঞ্জ হয়ে গেল, এখনে function scope কাজ করল নাহ? যদি এইখানে function scope কাজ না করে থাকে তাহলে a এর ভেলু যখন 1 দিলেন এবং বললেন যে এইটাও passByReference তাহলে এইটাও বাহিরে চেঞ্জ হওয়ার কথা ছিল এইটা কেন হল নাহ? function scope এর জন্য অবশ্যই নাহ? কারণ একটায় function scope কাজ করবে আর একটায় কাজ করবে নাহ তা তো আর হতে পারে নাহ। তাহলে কি এইটা Heap & Steak এর জন্য? a এর value যে passByReference সেটা প্রমাণ করে দেখাতে পারলে ভাল হত যেমন object টা করে দেখিয়েছেন।
Pointer দিয়ে চেঞ্জ করলে যেখানেই থাকুক চেঞ্জ হয়ে যাবে।
এ আলোচনা থেকে বোঝা গেলো যে, " জাভাস্ক্রিপ্ট " খুবই আলসে, শুধু রেফারেন্স কপি করে।😂😂😅
Awesome
Great