Value Types and Reference Types in JavaScript

  Рет қаралды 16,120

Programming with Mosh

Programming with Mosh

7 жыл бұрын

🔥Get the COMPLETE COURSE (60% OFF - LIMITED TIME): programmingwithmosh.com/cours...
Are you confused about value types and reference types? This tutorial makes it super simple for you.
You can find all my courses here:
programmingwithmosh.com/courses

Пікірлер: 31
@trappedcat3615
@trappedcat3615 7 жыл бұрын
x = x.toUpperCase() is the same as x.title = x.title.toUpperCase(). Both are mutable when we reassign a value.
@user-xs3ic2hi9o
@user-xs3ic2hi9o 7 жыл бұрын
im agree. The example is not the best... It is not correct, because i can say:"Reference Types are Immutable" because you run this: var x = {title: 'apple'}; x.title.toUpperCase(); and the title attribute does not change: x.title -> "apple"
@llimacruz
@llimacruz 7 жыл бұрын
At the first time I also thought it was wrong, but look what I've found: "Consider an integer like var x = 1 - if I write x += 1, I haven’t incremented the number 1 itself, I’ve just changed the variable x to have a new value, 2." Got it? smallcultfollowing.com/babysteps/blog/2014/04/01/value-types-in-javascript/ I know that Mosh wouldn't make a mistake about it.
@romainvincent7346
@romainvincent7346 7 жыл бұрын
I believe the very importance of value/reference comes with functions. Here is an example : x = "foo" y = { title: "foo" } (function(param){ param = 'bar' }(x)) // x == foo (function(param){ param.title = 'bar' }(y)) // y == bar First case, nothing changed because we changed a value which exists only inside the function block. But for the second case, we had a reference and we indeed modified the property title of the referenced object.
@mironoordzij4089
@mironoordzij4089 2 жыл бұрын
I mean he just reassigned the veriable being referenced, you can do the exact same thing with a primitive. Different? var x = 'apple' document.write(x) document.write(x.toUpperCase()) document.write(x) x = x.toUpperCase() document.write(x) document.write('') var y = {fruit:"melon"} document.write(y.fruit) document.write(y.fruit.toUpperCase()) document.write(y.fruit) y.fruit = y.fruit.toUpperCase() document.write(y.fruit)
@jyotirmoymukhopadhyay5077
@jyotirmoymukhopadhyay5077 9 ай бұрын
var s = "hi" var s1 = s console.log(s1) s = s.toUpperCase() console.log(s1) var obj1 = { name: "Tyler", age: 30, hobbies: ["running", "coding"] } var obj2 = obj1 console.log(obj2) obj1.age = obj1.age + 1 console.log(obj2) i think this can be a good example @@llimacruz
@user-uo9rz2fe9h
@user-uo9rz2fe9h 7 жыл бұрын
To explain like a boss.
@aryashacharya_world7143
@aryashacharya_world7143 6 жыл бұрын
thanks you sir its very helpfull...and first time i am commenting on any video.great work.
@MoT-MasterOfThings
@MoT-MasterOfThings 6 жыл бұрын
Very clear explaination
@sanfordhoffman2392
@sanfordhoffman2392 7 жыл бұрын
Great explanation
@08-avinashs10
@08-avinashs10 2 жыл бұрын
Fabulous Mosh 😀 you make it so simple
@keifer7813
@keifer7813 Жыл бұрын
What a great video. I understand it now
@mviniciuspolegario4794
@mviniciuspolegario4794 3 жыл бұрын
Amazing!!!!
@adrian-4767
@adrian-4767 7 жыл бұрын
Amazing! :D
@shyamraosravanth1954
@shyamraosravanth1954 3 жыл бұрын
good explanation sir
@javascript_developer
@javascript_developer 3 жыл бұрын
Great. Thanks. Is value types and primitive types are same?
@AbdullahAtya
@AbdullahAtya Жыл бұрын
This is really helpful :)
@BlockchainDaddy
@BlockchainDaddy 7 жыл бұрын
Subbed!
@waex7089
@waex7089 6 жыл бұрын
thanx
@sardarzain2551
@sardarzain2551 Жыл бұрын
Amazing 🤩🤩🤩🤩
@07UMARJAN
@07UMARJAN 7 жыл бұрын
hello Mr. Mosh, are you planing to do any pluralsight course soon? thanks
@07UMARJAN
@07UMARJAN 7 жыл бұрын
Like for instance , " Xamarin Forms Tutorial: Build Native Mobile Apps with C#" could have a playlist seprately("Xamarin Tutorial") like "Backbone.js Tutorial". Thank you
@pedroagma4417
@pedroagma4417 2 жыл бұрын
Would anybody know what "text editor/console" Mosh uses? It seems useful, having results calculated and everything but: what does he use? Thank you!
@simasgradeckas4259
@simasgradeckas4259 Жыл бұрын
It seems just like a built-in browser console :)
@sreenivasulugattu2936
@sreenivasulugattu2936 4 жыл бұрын
However, if we compare x.title === y.title, it will return true;
@TT-ud5gf
@TT-ud5gf 3 жыл бұрын
Is string really a value type?
@javascript_developer
@javascript_developer 3 жыл бұрын
That is what mentioned in the video. If a two same string variable are compared to each other , they return true
@AlvaroDoune
@AlvaroDoune 7 жыл бұрын
please, make a tutorial of Firebase! many thanks
@AlvaroDoune
@AlvaroDoune 7 жыл бұрын
great mosh, but I already bought 2 courses and I don't need to learn Angular because I work every day with this framework in my job! :)
@AD-wg8ik
@AD-wg8ik Жыл бұрын
let x = 'apple' x = x.toUpperCase() x = 'APPLE ' That's essentially what you did for the object.
@pedro7851
@pedro7851 Жыл бұрын
Yeah, he didn't assign the x.toUpperCase() to the x variable like he did to the title property of the x object...
JavaScript - Reference vs Primitive Values/ Types
20:56
Academind
Рет қаралды 149 М.
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 49 МЛН
когда достали одноклассники!
00:49
БРУНО
Рет қаралды 3,5 МЛН
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 767 М.
JavaScript Bitwise Operators
9:26
Programming with Mosh
Рет қаралды 98 М.
JavaScript Value vs Reference Types
6:48
Programming with Mosh
Рет қаралды 95 М.
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,1 МЛН
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
ES6 Tutorial: Learn Modern JavaScript in 1 Hour
50:05
Programming with Mosh
Рет қаралды 968 М.
Reference Vs Value In JavaScript
15:12
Web Dev Simplified
Рет қаралды 178 М.
C# Programming Tutorial 10 - Value Types and Reference Types
8:12
JavaScript Getters and Setters | Mosh
6:37
Programming with Mosh
Рет қаралды 234 М.
Is Coding Still Worth Learning in 2024?
9:33
Programming with Mosh
Рет қаралды 210 М.
What is Factory Function in JavaScript? - JS Tutorial
17:31
ColorCode
Рет қаралды 53 М.
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 49 МЛН