• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

248
Views
javascript websocket error, I want to get event.data in global scope

I want extract real time data from binance websocket. but result error.

let socket = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@trade");

        socket.onmessage = function(event){
        let current_price = JSON.parse(event.data);
        
        // console.log(current_price); :is okay!

        return current_price;
        }

let Data = socket.onmessage();

console.log(Data); :not okay..

even.data in function scope has no error,
but event.data not in function scope has this error.
Uncaught TypeError: Cannot read properties of undefined (reading 'data')

I want to get even.data in global scope.

plz help.

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error