Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
Returning a value from an imported function

This may be a simple problem but I can't get my head around it. I have a javascript file that looks like this:

import { canWeCamera } from './modules/_canWeCamera.js';
import { qrReader } from './modules/_qrReader.js';


function init() {
    
    canWeCamera();
    // Need to only run the function below if there is a camera
    qrReader();
  
}
  
init();

And the canWeCamera import looks like this:

export function canWeCamera() {

    if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
        console.log("enumerateDevices() not supported.");
    }
      
      navigator.mediaDevices.enumerateDevices()
      .then(function(devices) {
        devices.forEach(function(device) {
          if(device.kind == 'videoinput') {
              alert('There is a video device');
          }
        });
      })
      .catch(function(err) {
        console.log(err.name + ": " + err.message);
      });

}

Which is all working as expected.

My next step is only running the qrReader function if there is a camera. I guess I need to return a variable from the canWeCamera function, but I can't get it to work.

If anyone has any pointers that would be great

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!