Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,209,485 members, 8,006,243 topics. Date: Monday, 18 November 2024 at 07:30 PM |
Nairaland Forum / Science/Technology / Programming / Pro JS Devs, Please Is This Variable Chaining (1015 Views)
How Can I Achieve This With React JS .. Devs Pls Get In NOW!!!! / Help Pro JS Programmers, I'm Losing My Mind. / So There Are Devs That Earn Up To 30k USD. (2) (3) (4)
Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 2:58pm On Jul 01, 2022 |
I'm still a noob learning to code in JS on my phone with grasshopper.. since you opened this thread, I'm sure you know what variable chaining means and probably what array indexing means? Okay I'll go straight to my question then.. While I was studying array indexing after learning about variable chaining, I say this code example that wanted to explain array indexing. Var groceries = [ 'apples' 'bananas' 'orange' ] ; Var Fruit = groceries [1] So after seeing that example and considering what I learnt from variable chaining, I made me wanna ask this. Can I also call this variable chaining since the value of the argument 'groceries' was assigned ( I think ) to the value of the argument 'fruit' ? If I were were being taught by a programming teaching I probably would have asked him that too but since I am teaching myself, I have to seek for answers somewhere else.. So please, any one with any Idea of the answer should please help me. Thanks alot. |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 3:43pm On Jul 01, 2022 |
still learning JS, but u can source for answers on stackoverflow or youtube(if you have data) |
Re: Pro JS Devs, Please Is This Variable Chaining by Tobedated(m): 2:53am On Jul 02, 2022 |
I don't really get your question but if your code is right 'fruits' is currently equal to 'banana' because index starts at 0 so apples index is 0 banana is 1 also i'll recommend you change the source you're learning from 'var' is nowadays obsolete you should be taught to use 'let' and 'const' instead 2 Likes |
Re: Pro JS Devs, Please Is This Variable Chaining by HealerC: 3:07pm On Jul 02, 2022 |
Do you mean optional chaining? |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 3:56pm On Jul 02, 2022 |
Chaining is common in programming languages Commonly used are optional and method chaining Which has nothing to do with your code above.. Nothing like variable chaining in JavaScript Refactor your question. 5 Likes |
Re: Pro JS Devs, Please Is This Variable Chaining by Xedmark: 6:20pm On Jul 02, 2022 |
Exactly what is your question? It's obvious you actually don't understand the code you've written. If the value of groceries is assigned to be the same as fruit. So exactly what is your question? cos I'm sure you know this has nothing to do with Chaining programming. 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 10:43pm On Jul 02, 2022 |
Tobedated:what if I wanna create a global variable ? I'll use let ? |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 10:46pm On Jul 02, 2022 |
GREATIGBOMAN:no offence but for you to say the bolded, then I don't think you know your JS well. In JS, sometimes variables can be assigned other variables. y = 17 ; x = y ; print (x) ; In the above example, x is given the value 17 since y holds the value 17. This means the number 17 would be printed. 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by rockok: 11:11pm On Jul 02, 2022 |
sixpathsofpain:this isn't variable chaining either. the essence of creating variables is to be able to reuse the value they hold in this case, you just saved yourself from writing x = 17 by using the value you saved in the variable y 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by niel63(m): 11:45pm On Jul 02, 2022 |
rockok: You dey drink beer? Abi na coffee as presumed? |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 11:54pm On Jul 02, 2022 |
sixpathsofpain: Maybe I don't Show me an article or a write up anywhere that specifically talks about variable chaining in JavaScript Apart from what I listed in my original post |
Re: Pro JS Devs, Please Is This Variable Chaining by rockok: 7:34am On Jul 03, 2022 |
niel63:So why do we create named variables? is it to chain variables or what? Are you referring to method chaining or function? |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 7:41am On Jul 03, 2022 |
sixpathsofpain:There's nothing like Variable Chaining in JavaScript and maybe in Programming too You're only assigning the value of y to x |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 7:46am On Jul 03, 2022 |
Nurudeen06:and that is called variable chaining. Google it |
Re: Pro JS Devs, Please Is This Variable Chaining by rockok: 8:10am On Jul 03, 2022 |
sixpathsofpain:you can only chain methods and not variables my friend. "you must be humble enough to accept when you are wrong to succeed in this field " -Sun Tzu |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 10:55am On Jul 03, 2022 |
sixpathsofpain: How about you yourself Google it |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 11:02am On Jul 03, 2022 |
sixpathsofpain: y = 17 ; x = y ; print (x) ; Front this your code.. If I come below and change y = 17 ; x = y y=20 x will still be 17 and doesn't track the state of y how is this chaining to you? ; 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 12:14pm On Jul 03, 2022 |
GREATIGBOMAN:I don't think x would still be 17 bro, because x is still equal to y which would make x be equal to 20 and not 17. Because you just reassigned a new value to y which is 20 and since x is still x=y, x would print as 20. Shey you get? |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 12:26pm On Jul 03, 2022 |
sixpathsofpain: shows u don't know javascript then... By doing the above... u are basically setting x = 17 and not y exactly, x doesnt track the state of y.... y was just a value.. Just checked and you're actually the original poster... well... 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by etoluw: 1:55pm On Jul 03, 2022 |
sixpathsofpain: Firstly i don't think there's anything like variable chaining in JS. What we have is method chaining or function chaining. And for your question x is still equal to 17 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by dEv400: 2:01pm On Jul 03, 2022 |
So much arrogance from someone who doesn’t know much … smh 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 2:08pm On Jul 03, 2022 |
dEv400: i wonder. from the way he's using print() u wonder what exactly he's trying to print in Js 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 2:12pm On Jul 03, 2022 |
dEv400:There's no one being arrogant here. I said there's stuff called variable chaining in JS, folks said there's no such thing. I'm trying to prove that such exist(according to what I've studied) and now you're saying I don't know much and I'm arrogant. Yes, I don't know much, no doubt, but with the little I know, I refuse to let anyone one who lacks any viable explanation to prove me wrong, just tell me that I'm wrong and expect me to swallow it unchecked. If that's what makes me arrogant, then let it be so. |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 2:16pm On Jul 03, 2022 |
sixpathsofpain: Define variable chaining in JS All your examples above are wrong and has nothing to do with chaining. Var groceries = [ 'apples' 'bananas' 'orange' ] ; Var Fruit = groceries [1] if i come below and change. Var groceries = [ 'Dog' 'rat', "puss" ] ; Fruits will still be "bananas". |||||||||||||||||||||||||||| y = 17 ; x = y ; print (x) ; From this your code.. If I come below and change y = 17 ; x = y y=20 x will still be 17 and doesn't track the state of y 1 Like |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 2:19pm On Jul 03, 2022 |
If you haven't heard of stuff and someone comes and says stuff exists, don't just come here and be saying blatter when you've not done your research just because you feel you're a pro. No one is an island of knowledge and according to one developer I idolise on this forum "them no dey learn JAVASCRIPT finish" |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 2:23pm On Jul 03, 2022 |
sixpathsofpain: As u learn further u will come back and modify ur posts 2 Likes |
Re: Pro JS Devs, Please Is This Variable Chaining by captainbangz: 2:33pm On Jul 03, 2022 |
Vawulence everywhere...lol |
Re: Pro JS Devs, Please Is This Variable Chaining by jbreezy: 2:58pm On Jul 03, 2022 |
sixpathsofpain:variable chaining?? Never heard of that. In your code, Fruit = 'bananas' and that's it. |
Re: Pro JS Devs, Please Is This Variable Chaining by Kvngfrosh(m): 3:02pm On Jul 03, 2022 |
sixpathsofpain:X will be 17 not 20 because it’s a primitive type not a reference type.
|
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 3:04pm On Jul 03, 2022 |
GREATIGBOMAN:wrong fruit can not remain = bananas. Fruit would now be assigned the 2nd string in the groceries array which is 'rat' as it's value. Because Var fruit is still = groceries [1]. If you want fruit to remain bananas you have to give it the value bananas , or else it would continue to bear the same value as the second item in the groceries array irrespective of what you update the items of the groceries array to be in the future because var fruit = groceries [1] if your want fruit to still remain as bananas, change var fruit = groceries [1] to var fruit = bananas |
Re: Pro JS Devs, Please Is This Variable Chaining by Nobody: 3:13pm On Jul 03, 2022 |
sixpathsofpain: The time you used typing this you would have used it to actually test the codes before posting. Kindly test all what you've written on the console. When you're done, This is "L" tag Add it a necklace and put it on your neck Bye 4 Likes |
Re: Pro JS Devs, Please Is This Variable Chaining by sixpathsofpain: 3:16pm On Jul 03, 2022 |
jbreezy:ok what if I now reassigned new values to the groceries variables but don't reassign a new value to the fruit variable, what would be the output of the code. groceries = [ 'condom' 'kayamata' 'refnol' Fruit = groceries [1] Then what would be the output ? Would fruit still remain bananas or would it change to 'kayamata' ? |
Alexis, Please Could You? / Selfawareness Can Be Achieved Via Artificial Intelligence? Anybody / Please, I Need The Activation Parameters For Internet Download Accelerator Or In
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 73 |