Y
Y
yoshi8882020-06-08 12:56:07
JavaScript
yoshi888, 2020-06-08 12:56:07

How to pass a variable to a function handler?

we have

function one() {

    var btn = document.querySelector("#reply");
    var x = 7;
    btn.addEventListener("click", two);

}

function two() {

console.log('как вывести икс');
console.log(x);

}

one()


how to pass the variable x from the first function to the second so that console.log(x); worked?5ede0ad513231181772851.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Loli E1ON, 2020-06-08
@yoshi888

Can be an argument

R
Rerurk, 2020-06-08
@Rerurk

Add to function one, return x
Console.log (one()) //// 7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question