Cannot create type as specific number when number is in variable

I want to create a type that can be only 1 or root 2. This works: type OneOrRootTwo = 1 | 1.4142135623730951; But when I try to use Math.SQRT2, or any variable reference to the numeric value of root …

How do I call JSON data stored as a variable in a different component?

I am currently drawing JSON data from my api using axios, and I am mapping this data and storing it as a variable. I want to be able to call these variables in my react components, but I can’t seem to …

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 …

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 if(localStorage….

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. {“sales”: { “total_sales”:”999.99″, …

is there a way to exchange variables between JavaScript and PHP

I have build a website in Drupal, and I am trying to create a fun way to get members involved with the site by building a userpoint system, the system is all in place, but I’m trying to make a shop …

Increase and decrease a variable until a number is reached in Javascript

How can I increase and decrease a variable in Javascript until 100 and when 100 is reached it should start decreasing. So accuracyBarValue should start in 0, increase to 100, and when 100 is reached …

Get all Javascript Variables?

Is there a way for javascript to detect all assigned variables? For example, if one js file creates a bunch of vars (globally scoped), can a subsequent file get all the vars without knowing what they’…

How can I determine if a variable is ‘undefined’ or ‘null’?

How do I determine if variable is undefined or null? My code is as follows: var EmpName = $(“div#esd-names div#name”).attr(‘class’); if(EmpName == ‘undefined’){ // DO SOMETHING };

What is the scope of variables in JavaScript?

What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally? Answer TLDR JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by looking at the source code. The four scopes are: Global – visible by everything Function – visible within a function (and its sub-functions and blocks) Block – visible within a block (and its sub-blocks) Module – visible within a module Outside