I've called myFunc
inside myFunc2
. Now what I want is to print var2
when I call myFunc2
using callback concept. I know something is wrong. The code I've tried isn't working.
It is showing this error:
Uncaught ReferenceError: newfunc is not defined(…)
How can I fix it?
CODE:
<html>
<head>
<title></title>
<script>
function myFunc(parameter){
var var2="another thing";
newfunc(var2);
}
function myFunc2(){
var var1="Something";
myFunc(newfunc(some));
console.log(var1);
console.log(var2);
}
</script>
</head>
<body>
<button onclick="myFunc2()">BUTTON</button>
</body>
</html>
EDIT:
According to comments, I didn't defien newfunc()
. Now I've defined it. But it's not working.
<script>
function myFunc2(){
var var1="Something";
myFunc(function newfunc(some){
console.log(var2);
});
console.log(var1);
}
function myFunc(parameter){
var var2="another thing";
newfunc(var2);
}
</script>