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

Комментарии • 114

  • @pretompauldip5179
    @pretompauldip5179 2 года назад +3

    Most underrated bangla programming content

  • @56faisal
    @56faisal 3 года назад +10

    এই প্রথম কোন বাংলা চ্যানেল এর প্রতিটা ভিডিও খুজে খুজে দেখতেসি। অসাধারন ভাই. চালিয়ে যান।

  • @kawsar.130
    @kawsar.130 2 года назад +1

    I was exactly looking for this.
    Lodash was the thing that I was looking for 3 days.
    Thank you for this video.

  • @h.m.zakariasumon1644
    @h.m.zakariasumon1644 3 года назад +3

    Your ability to explain is amazing. Thank you very much.

  • @atiqurrahman9679
    @atiqurrahman9679 3 года назад +1

    vaia you are awesome ........ so many many thanks

  • @sajjadahmed9528
    @sajjadahmed9528 3 года назад +1

    আপনার সব টিউটোরিয়াল সেরা স্যার।আপনি আগা গোড়া সব বিষয় গুলো explain করেন।আমার দেখা মতে বাংলাতে এমন কোন টিউটোরিয়াল নেই যে আপনার মতো এতো detail বুঝিয়ে দেয়। আপনি প্রোগ্রামিংকে আমাদের মাঝে অনেক আলাদাভাবে প্রকাশ করেছেন।প্রোগ্রামিংয়ের boringness কাটিয়ে তুলে প্রোগ্রামিংকে ভালোবাসতে শিখিয়েছেন।
    কে কি বলে জানিনা তবে আপনি সত্যি প্রোগ্রামিং বা জাভাস্ক্রিপ্ট এর বস।ঠিক আপনি যেভাবে নিজে বোঝেন ঠিক সেই ভাবেই নিজের বুঝ মানুষের কাছে প্রকাশ করেন।যা সবাই পারেনা।
    ভালোবাসা নিবেন প্রিয় স্যার ❣️🥰😍❣️💞💕💞

  • @gojo55x
    @gojo55x Год назад

    Best Video on RUclips about this topic take Love Sir 💙

  • @nivreet4058
    @nivreet4058 2 года назад +1

    super informative.. amazing teaching skill, everything is crystal clear

  • @mukulhasan6144
    @mukulhasan6144 Год назад

    খুবই গুরুত্বপূর্ণ এবং তথ্যবহুল একটি ভিডিও। ধন্যবাদ আপনাকে সুমিত স্যার।

  • @ratulislam1784
    @ratulislam1784 2 года назад +1

    sir thank you for your this type concept

  • @softwareengineer7802
    @softwareengineer7802 Год назад

    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

  • @nazmulhossain8297
    @nazmulhossain8297 Год назад

    great vai ...your explanation masaallah

  • @harmonywithin8084
    @harmonywithin8084 11 месяцев назад

    well explained vai...keep going forward

  • @zubayersalehin1164
    @zubayersalehin1164 2 года назад +1

    Nice video keep it up bro

  • @hasanimruz5195
    @hasanimruz5195 3 года назад +1

    onek kisu clear holo Thanks

  • @farzanayasmin1104
    @farzanayasmin1104 Год назад

    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

  • @shahriarhossain839
    @shahriarhossain839 5 месяцев назад

    Learned a lot of things dada

  • @s.m.emonislam1446
    @s.m.emonislam1446 2 года назад

    Awesome explanation.

  • @learnwithbillal6185
    @learnwithbillal6185 2 года назад

    অনেক ভিডিও দেখে এই বিষয়ে ক্লিয়ার হইনি।
    অবশেষে আপনার ভিডিও দেখে পানির মতন ক্লিয়ার হয়ে গেলাম
    ভাই, আপনাকে অসংখ্য ধন্যবাদ।

  • @rajibulhasan7676
    @rajibulhasan7676 2 года назад

    So good, so Informative

  • @suptohossein7729
    @suptohossein7729 2 года назад

    wow, just amazing

  • @braintricker_soft
    @braintricker_soft 3 года назад

    vaia you are awesome :) international standard er video .. thank you

  • @saifulislamniloy1107
    @saifulislamniloy1107 3 года назад

    Amazing Explanation. 😍

  • @MubasshirMiraj
    @MubasshirMiraj 2 года назад

    Amazing explanation. 💖💖

  • @imranhossain3511
    @imranhossain3511 2 года назад

    excellent video vaiya

  • @aristocracyhorain9355
    @aristocracyhorain9355 3 года назад +1

    Thanks a lot. Bhaiya

  • @rifatulislam4184
    @rifatulislam4184 3 года назад

    Nice presentation.

  • @md.abusalman8874
    @md.abusalman8874 2 года назад

    Sir, Thank you.

  • @ashikghosh6166
    @ashikghosh6166 2 года назад

    সুন্দর!

  • @aburaihan-py4vi
    @aburaihan-py4vi 3 года назад

    Excellent!

  • @anamulhoq6948
    @anamulhoq6948 3 года назад

    Keep continue good jobs

  • @ahq8571
    @ahq8571 2 года назад

    Awesome

  • @bishwajitdebnath
    @bishwajitdebnath 2 года назад

    It's really the best tutorial for javascript lovers. Love you, sir.

  • @firsttnameelasttnamee4583
    @firsttnameelasttnamee4583 3 года назад

    Just woow, vy

  • @abdullahalsiam105
    @abdullahalsiam105 3 года назад +4

    Another masterpiece

  • @sauravdas51
    @sauravdas51 3 года назад +1

    amazing teaching skill, everything is crystal clear

    • @LearnwithSumit
      @LearnwithSumit  3 года назад +1

      Thanks. Please subscribe if you find this video useful and take a look at other videos in this channel.

  • @hellboynahid6873
    @hellboynahid6873 Год назад

    Great

  • @mehedimazumder9378
    @mehedimazumder9378 3 года назад

    😯😮 super informative..

    • @LearnwithSumit
      @LearnwithSumit  3 года назад

      Thanks. Please share as much as you can if you like these contents.

  • @md.riduanulhaque5812
    @md.riduanulhaque5812 3 года назад

    Primitives' and reference er importance ta bujhlam. age ato important mone kortam na. Thanks Bhaiya. :-)

    • @LearnwithSumit
      @LearnwithSumit  3 года назад

      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

  • @abujafarsiddique7635
    @abujafarsiddique7635 3 года назад

    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.

  • @dardaC137
    @dardaC137 3 года назад +1

    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

  • @md.mohiulislam6516
    @md.mohiulislam6516 Год назад

    you are specially blessing for non-CSE student 💙🤍💙.

  • @Yua_5
    @Yua_5 3 года назад

    Thanks 😍

  • @anisahad8025
    @anisahad8025 Год назад

    thanks

  • @tanvir5075
    @tanvir5075 3 года назад +1

    Bro, you are doing great!!

  • @redone7524
    @redone7524 3 года назад +2

    Sir , Difference between Stack and Heap memory in javascript , এই সম্পর্কে একটা টিউটোরিয়াল দিবেন প্লিজ

  • @abulkalamazad6022
    @abulkalamazad6022 3 года назад

    Excellent explanation!!!

  • @fazlechistyhimel3958
    @fazlechistyhimel3958 2 года назад

    দাদা আপনার ভিডিও দেখে অনেক অনেক উপকৃত হয়েছি। অনেক কিছু শিখেছি। আরকেটা আবদার কী করতে পারি? জাভাস্ক্রিপ্ট অবজেক্ট অরিয়েন্টেড প্রোগ্রামিং নিয়ে একটা প্লে লিস্ট ?

  • @mohammadmahbubtalukder3824
    @mohammadmahbubtalukder3824 2 года назад

    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))

    • @LearnwithSumit
      @LearnwithSumit  2 года назад

      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

  • @MasudRahman-kr9kx
    @MasudRahman-kr9kx Год назад

    আমার দ্বারা সম্ভব হলে কয়েক billion likes দিতাম👍👍

  • @habibulislam3386
    @habibulislam3386 2 года назад +1

    why not JSON.parse(JSON.stringify(object)) instead of lodash?

  • @rahadulhaq6387
    @rahadulhaq6387 2 года назад

    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

  • @alakdas4662
    @alakdas4662 3 года назад

    amazing content

  • @tangilurrahman
    @tangilurrahman 2 года назад

    ❤️❤️❤️

  • @MA-np7if
    @MA-np7if 3 года назад

    ভাইরে আপনার টিউটোরিয়ালগুলো কতটা সেরা হচ্ছে বলে বোঝাতে পারবনা। প্রিমিয়াম কোর্সগুলোও এভাবে বোঝায়না। ❤️❤️❤️

    • @LearnwithSumit
      @LearnwithSumit  3 года назад +1

      ধন্যবাদ ভাই। subscribe করতে ভুলোনা।

    • @MA-np7if
      @MA-np7if 3 года назад

      @@LearnwithSumit অনেক আগেই করে রেখেছি।😍

  • @easinwebpro
    @easinwebpro 3 года назад

    🤟🤟🤟Supper 🤟🤟🤟😍😍😍

  • @zabirabdullah6914
    @zabirabdullah6914 3 года назад +1

    দাদা, সুধু কলব্যাক নিয়ে একটা টিউটোরিয়াল দিবেন প্লিজ।

  • @siblshivpur3010
    @siblshivpur3010 2 года назад

    rocket informative

  • @MBUniqueTech
    @MBUniqueTech 7 месяцев назад

    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

  • @sushibilai
    @sushibilai 2 года назад

    sir stack er video link ta ki dewa zabe eta khuje pacchina ba pele o bujhtechina

  • @mdsafikulislam9113
    @mdsafikulislam9113 3 года назад

    Stack somporke kon video te bola hoyeche bhai ...

  • @arnobroy6292
    @arnobroy6292 2 года назад

    primitive value pass by reference hoy?

  • @masudrana1983
    @masudrana1983 3 года назад +1

    awesome..
    but vscode e ki font use koren eta ektu bolen.

    • @LearnwithSumit
      @LearnwithSumit  3 года назад

      Fira Code (Free) and Operator Mono (Paid)

  • @user-vi7sy3nu3i
    @user-vi7sy3nu3i 4 месяца назад

    🥰🥰🥰🥰🥰

  • @SSakibHossain10
    @SSakibHossain10 3 года назад +1

    ❤❤❤❤❤

  • @hossianrabbi3980
    @hossianrabbi3980 3 года назад

    ভাইয়া, JavaScript Iterators নিয়ে যদি একটা ভিডিও দিতেন, উপকার হইতো.

  • @SuperAlipriya
    @SuperAlipriya 3 года назад

    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??

    • @LearnwithSumit
      @LearnwithSumit  3 года назад +1

      disadvantage nai. tobe ektu boro object hole ei technique ta slow

  • @md.redwanhossain8822
    @md.redwanhossain8822 Год назад

    Behind the scene, array/object passes its value as pointer. A C programmer can feel this low level concept very easily.

  • @MubasshirMiraj
    @MubasshirMiraj 2 года назад

    Vaia, deeply copy javascript এর মাধ্যমে কীভাবে করব?lodash use না করে। বললে খুবই উপকৃত হতাম। please

  • @md.saifulislam6528
    @md.saifulislam6528 Год назад

    24:47 nothing to say, Man!!! (At this time I could not but laugh)

  • @avimonnudash1762
    @avimonnudash1762 3 года назад

    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?

    • @LearnwithSumit
      @LearnwithSumit  3 года назад +1

      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.

  • @ashraful07
    @ashraful07 3 года назад +1

    Vai react or node nea course start koren

  • @shaonsikdar8738
    @shaonsikdar8738 7 месяцев назад

    ❤❤❤ 02 Dec, 2023

  • @moazmahmud4285
    @moazmahmud4285 2 года назад +1

    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.

    • @md.redwanhossain8822
      @md.redwanhossain8822 Год назад

      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)

    • @md.redwanhossain8822
      @md.redwanhossain8822 Год назад

      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.

    • @moazmahmud4285
      @moazmahmud4285 Год назад

      @@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.

    • @md.redwanhossain8822
      @md.redwanhossain8822 Год назад

      @@moazmahmud4285 I explained in terms of C, I need to explore more about C++

  • @blackpro5763
    @blackpro5763 3 года назад +1

    আমি আগে অবজেক্ট কপি করতে
    var b = JSON.parse(JSON.stringify(a));
    এই মেথড ইউজ করতাম। আপনার মন্তব্য জানতে চাই এটি নিয়ে। এর কোনো ডাউনসাইড আছে কি?

    • @LearnwithSumit
      @LearnwithSumit  3 года назад +4

      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.

    • @blackpro5763
      @blackpro5763 3 года назад

      @@LearnwithSumit thanks vai 😍 for such detail explanation. I will go with lodash

    • @mdtazri388
      @mdtazri388 3 года назад

      >>> @@LearnwithSumit wow. আমার মাথায় একই প্রশ্ন ঘুরছিল এই ট্রিকটা থাকতে কী জন্য lodash ব্যবহার করবো? এখন সম্পর্ন্ন clear হয়ে গেছে। Thank you very very so much:)

  • @mohammadnaim9226
    @mohammadnaim9226 2 года назад

    another diamond

  • @riduanulhaque4748
    @riduanulhaque4748 3 года назад

    :-)

  • @raselmahamud948
    @raselmahamud948 3 года назад +1

    যখন function এর ভিতর object দিলেন সেটা passByReference এর কারণে বাহিরে ও চেঞ্জ হয়ে গেল, এখনে function scope কাজ করল নাহ? যদি এইখানে function scope কাজ না করে থাকে তাহলে a এর ভেলু যখন 1 দিলেন এবং বললেন যে এইটাও passByReference তাহলে এইটাও বাহিরে চেঞ্জ হওয়ার কথা ছিল এইটা কেন হল নাহ? function scope এর জন্য অবশ্যই নাহ? কারণ একটায় function scope কাজ করবে আর একটায় কাজ করবে নাহ তা তো আর হতে পারে নাহ। তাহলে কি এইটা Heap & Steak এর জন্য? a এর value যে passByReference সেটা প্রমাণ করে দেখাতে পারলে ভাল হত যেমন object টা করে দেখিয়েছেন।

    • @md.redwanhossain8822
      @md.redwanhossain8822 Год назад

      Pointer দিয়ে চেঞ্জ করলে যেখানেই থাকুক চেঞ্জ হয়ে যাবে।

  • @marufhasan21
    @marufhasan21 2 года назад

    এ আলোচনা থেকে বোঝা গেলো যে, " জাভাস্ক্রিপ্ট " খুবই আলসে, শুধু রেফারেন্স কপি করে।😂😂😅

  • @fahimal-huq6867
    @fahimal-huq6867 3 года назад

    Awesome

  • @sazzad_karim
    @sazzad_karim 2 года назад

    Great