I’m building a calculator app and like the title states, I want to find a way where I can store my ‘display value’ in a variable to be used in math functions (+ – * /). The buttons do display as expected but the next use case would be to capture that value and place it in a variable. Let
Tag: variables
How to listen to external variable changes in React
Hope you’re doing well 🙂 I’ve an “auth.js” file, with an aysnc function to get the userId and then store it in session storage. Here it is: Then I access this variable in all components that need it, in order to make other requests. Example in App.js: The problem is that, in the first render, the userId comes null (obviously)
Why do I need this. keyword to reference a variable with the same name?
Good evening, This is my first post on stack overflow. I’m a newbie in programming and I can do many things in C++ – a language I love. However, recently I’ve moved on to javascript with the mission of getting hired. I’m creating a snake game and I’m automatizing its moves. I just do not understand why a variable I
how do i copy an array correctly
im trying to make a copy of an array but when i change the copy it also changes the original. i have tried using Object.assign([], scenes), scenes.clone() and tried using a for loop Answer You can also try const arrayCopy = JSON.parse(JSON.stringify(initialArray)), although the method using the spread operator should work as well.
Access nested JSON with month numbers
i got an json file with monthly values. i need to access these. I am not able to archive this. Maybe i just make an mistake. How can i get the value from the second “sales” with 9.99? I use JS to get the total_sales. This works. I really need you help for this. For more clearence: The JSON-File is
Why is the variable `closed` being logged as `false`, if I define it globally as `0`?
I know this must be really basic stuff but I don’t understand how the scope is working. I want the closed variable be known in the entire JavaScript file. I have something like that (in jQuery): But closed is getting logged as false. I tried many things with load and onload functions, but I failed. Answer Use let instead of
Check if variable is false and not either true or undefined
What’s the best way to check if myvar javascript variable === false or not (it may be undefined as well). would be fine but myvar it could be undefined. Only false value is acceptable, not undefined. Any shorter than if (typeof myvar !== “undefined” && myvar === false)? Answer If the variable is declared then: will work fine. === won’t
javascript variable and value concatenation
I have a list of variables: What i would like to do, is insert the value of a given variable from the option options, into an element, but the ‘number’ of the variable (ie, 1, 2 or 3) is itself coming in as a variable, say itemNumber. What I would like to do is: $(element).html(subcatlist+ itemNumber); … Which would give
how to pass csrf_token to javascript file in django?
Here is my javascript code that works fine. but I like to keep javascript files seperate and not use as inline script tags I want to include this in my custom.js file that I have included in my base.html. which is I am not able to reference csrf_token that is available in the current template in Django to the static
What’s the difference between a string and an array of characters in Javascript?
When I checked if these two were equal, they apparently weren’t. Can someone explain why? Why is (string === array) is false ? EDIT: This website is fantastic. Such fast help. Thanks guys. Answer Why is (string === array) is false ? You are using strict comparison (===), which also checks the data type of the values. Obviously a primitive