About 2,160,000 results
Open links in new tab
  1. How to access Javascript variable values outside of the function

    What I would like to do is have access to the values set in an array within a function but outside of that function. How could this be done? For example: profile = []; profile[0] = "Joe"; profile[1] = "Bloggs"; profile[2] = "images/joeb/pic.jpg"; profile[3] = "Web Site Manager";

  2. javascript - Accessing variables from other functions without …

    Jan 2, 2009 · Consider using namespaces: (function() { var local_var = 'foo'; global_var = 'bar'; // this.global_var and window.global_var also work function local_function() {} global_function = function() {}; })(); Both local_function and global_function have access to all local and global variables. Edit: Another common pattern: var ns = (function ...

  3. Javascript Variable outside of function? - Stack Overflow

    It would probably be best to wrap the code in a self executing function to prevent global pollution. Another alternative would be to define move.count=1 instead of count, and just work of the already defined more() global variable .

  4. How to access variable outside function in JavaScript | Code

    May 26, 2022 · To access a variable outside a function in JavaScript make your variable accessible from outside the function. First, declare it outside the function, then use it inside it.

  5. JavaScript Scope - W3Schools

    Variables defined inside a function are not accessible (visible) from outside the function. Variables declared with var, let and const are quite similar when declared inside a function. They all have Function Scope: A variable declared outside a function, becomes GLOBAL. A …

  6. How to Get Variable Value Outside Function in JavaScript?

    Dec 6, 2024 · Accessing a variable’s value outside a function in JavaScript depends on how and where the variable is defined. By utilizing return statements, global variables, callbacks, closures, or promises, you can effectively retrieve and work with values outside of a function’s scope.

  7. How to access value defined outside a function in Javascript

    In JavaScript, you can access a value defined outside a function within the function by using the variable's name. Variables declared outside a function are in the global scope, making them accessible throughout the entire script.

  8. How to access variable outside of function scope in JavaScript, …

    Oct 14, 2023 · In ReactJS and TypeScript, you can access variables outside of function scope by using the "this" keyword. The "this" keyword refers to the current instance of the class or component and allows you to access its properties and methods.

  9. Variable scope, closure - The Modern JavaScript Tutorial

    Jun 13, 2022 · We already know that a function can access variables outside of it (“outer” variables). But what happens if outer variables change since a function is created? Will the function get newer values or the old ones?

  10. Referencing a variable outside a function - JavaScript - The ...

    Jun 16, 2018 · This is the updated code: // alert('Is this mike on?') var myList = document.querySelector('ul'); var myInput = document.querySelector('input'); var myButton = document.querySelector('button'); var mySecondButton = document.createElement("button"); mySecondButton.classList.add("invisible"); // myButton.onclick = function() {

  11. Some results have been removed
Refresh