Home > Article > Web Front-end > js callback simple code example
This article mainly shares a simple code with you, which is a simple code example for js callback. I hope this code can help everyone.
function test(callback) { var data = "aaa"; typeof callback == 'function' && callback(data) } test(function (data) { console.log(data); });
typeof callback 输出callback的类型 == 'function' 等于function(函数)&& callback(data) &&前面的为真,则执行&&后面的语句 callback(data), data为需要传递的函数参数,
Related recommendations:
A simple example of the application of JS callback function_javascript skills
Blocking and non-blocking calls of node.js callback functions_node.js
The above is the detailed content of js callback simple code example. For more information, please follow other related articles on the PHP Chinese website!