Passing Value from one function to another JS

how to use one function variable in another function in javascript
how to pass value from one $ function to another $ function in jquery
how to get value from one function to another in javascript
pass variable from one function to another python
access variable from another function javascript
how to pass variable from one script to another in javascript
how to pass dynamic value in javascript function
how to pass object from one function to another in javascript

following problem

I got 2 functions

This is my onInit:

onInit: function() {
        sap.ui.core.UIComponent.getRouterFor(this).getRoute("CoObject").attachMatched(this._onRouteMatched, this);

    _onRouteMatched: function(oEvent) {
        var sRoute = oEvent.getParameter("arguments").Route;

and I need to use the Value of sRoute in this function:

_onWeiterButtonPress: function(oEvent) {
    var oRouter = this._getRouter();
    var AufNr = this.getView().byId("IptAufNr").getValue();

In need sRoute to check which tile the user pressed but I don´t know how to pass the value without setting in global?

Thanks for your Help

I think a solution can be to set the sRoute value on sessionStorage and use it in _onWeiterButtonPress. Here is an example:

sessionStorage.setItem('sRoute', sRoute);//for set the value
sessionStorage.getItem('sRoute';//for get the value

How can I pass a value from one function to another function without , (function(){ var a, c; // Not global, but available to all three functions function new1 (){ a = 5; } function new2(){ c = 6; } function new3(){ if(a < c)� I tried the following, trying to pass a variable from one JavaScript file to another JavaScript variable. My first JavaScript file: var x = "sachin"; My other JavaScript file can't access that x variable value. How do I solve this? I can access that x variable and same value in another file.

How about this:

_onRouteMatched: function (oEvent) {
        var sRoute = getArgumentsFromRoute(oEvent);

_onWeiterButtonPress: function (oEvent) {

        var oRouter = this._getRouter();
        var AufNr = this.getView().byId("IptAufNr").getValue();
        var sRoute = getArgumentsFromRoute(oEvent);

function getArgumentsFromRoute(oEvent)
        return oEvent.getParameter("arguments").Route;

javascript, Hello jaycastr,. A variable declared inside a JavaScript function will only be local if you write it like this: function func(){ var x = 5; }. However� It creates a local variable and passes its value to another function. The second function creates a global variable and sets a value in the first function. When the second function is called from the first function, a local variable is declared using the value of the global variable (set in the first function). – Proto Jul 21 '17 at 12:50

You can pass on objet as second parameter of the navTo methode.

    onWeiterPressed: function (oEvent) {

        this.getRouter().navTo("detailView", {
            aufNr: this.getView().byId("IptAufNr").getValue();


and then in the view you navigated to:

    _onRouteMatched: function (oEvent) {

        // Get passed object
        var sObjectId = oEvent.getParameter("arguments").aufNr;


All written in the documentation ;)

Chapter 15. Functions, In JavaScript, you cannot pass parameters by reference; that is, if you pass a variable to a function, its value is copied and handed to the function (pass by value). Therefore, the function can't change the variable. If you need to do so, you must wrap the value of the variable (e.g., in an array). Assign function Recursive function Passing functions as parameter of another function. examples/functions/passing_function.js

Solved it whit help from @santhosh by declaring

_onRouteMatched: function(oEvent) {
    this.sRoute = oEvent.getParameter("arguments").Route;

now I can navigate from the one View to 3 different views depanding on which Tile the User clicked.

Thx alot

Javascript to pass value from one function to another function , was developing application to calculate cuf where user selects one of the option in the drop down menu For example if user selects hour . When I run the console.log as follows in the initialize function defined in the code below: console.log("Checking for Value_Of_Process_Type in Initialize Function ! :" +Value_Of_Process_Type

Ways of passing data to functions in JavaScript, This is done by passing values in parenthesis: myFunction(myData). This example only passes one variable to the function. Note that all it takes to overwrite another function is to redeclare a function with the same name. React Native Passing Value between Screen. While creating an app containing multiple screens, then sometimes it is required to pass value between one screen to another. This can be achieved by using this.props.navigation.navigate() function. This function is used to navigate between the different screens.

JavaScript Callback Functions, Specifically, this video covers: a) Passing JavaScript Functions as Variables as a parameter Duration: 6:18 Posted: Feb 24, 2016 Pass event handlers and other functions as props to child components: < button onClick = { this . handleClick } > If you need to have access to the parent component in the handler, you also need to bind the function to the component instance (see below).

[Javascript] Pass By Value And Pass By Reference In JavaScript, Pass by Value: In Pass by Value, Function is called by directly passing the value of the variable as the argument. Changing the argument inside the function doesn't affect the variable passed from outside the function. I'm fairly new at this. I'm trying to build a store locator and trying to figure out how to pass an input value from one page to another page. User would input their zipcode or address in a form