Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

417
Visualizações
Fix - expected an assignment or function call and instead saw an expression

I am trying to fix this Eslint error:

Expected an assignment or function call an instead saw an expression

Any idea on how I can accommodate the code so that it doesn't give me that error in following sample code?

window.matchMedia || (window.matchMedia = function() {
 
  if (!styleMedia) {
    const style = document.createElement('style');

    const script = document.getElementsByTagName('script')[0];

    let info = null;

    style.type  = 'text/css';
    style.id    = 'matchmediajs-test';

    script.parentNode.insertBefore(style, script);

    info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle;

    styleMedia = {
      matchMedium: function(media) {
        const text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }';

     
        if (style.styleSheet) {
          style.styleSheet.cssText = text;
        } else {
          style.textContent = text;
        }

        return info.width === '1px';
      },
    };
  }

  return function(media) {
    return {
      matches: styleMedia.matchMedium(media || 'all'),
      media: media || 'all',
    };
  };
}());

Any idea why I am getting this lint error?

Thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your first line (which encloses the whole script, actually)

window.matchMedia || (window.matchMedia = function() {

is an expression, not an assignment or function call. You instead need something like:

if (!window.matchMedia) {
  window.matchMedia = function() {
    // ..
}

instead of assigning inside the conditional.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda