title: Rendering PDF with pdf.js
body: <p>I'm new in javascript. I'm Trying to render a pdf with pdf.js. and I get this error:<br>
  <code>Parsing Error: Unexpected token const </code></p>
  <p>from this code:<br>
  <code>const url = '../docs/pdf.pdf';</code></p>
  <p>My Code</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const url = '../docs/pdf.pdf';
  
  let pdfDoc = null,
    pageNum = 1,
    pageIsRendering = false,
    pageNumIsPending = null;
  
  const scale = 1.5,
    canvas = document.querySelector('#pdf-render'),
    ctx = canvas.getContext('2d');
  
  
  const renderPage = num =&gt; {
    pageIsRendering = true;
  
  
    pdfDoc.getPage(num).then(page =&gt; {
     
      const viewport = page.getViewport({ scale });
      canvas.height = viewport.height;
      canvas.width = viewport.width;
  
      const renderCtx = {
        canvasContext: ctx,
        viewport
      };
  
      page.render(renderCtx).promise.then(() =&gt; {
        pageIsRendering = false;
  
        if (pageNumIsPending !== null) {
          renderPage(pageNumIsPending);
          pageNumIsPending = null;
        }
      });
  
     
      document.querySelector('#page-num').textContent = num;
    });
  };
  
  
  const queueRenderPage = num =&gt; {
    if (pageIsRendering) {
      pageNumIsPending = num;
    } else {
      renderPage(num);
    }
  };
  
  
  const showPrevPage = () =&gt; {
    if (pageNum &lt;= 1) {
      return;
    }
    pageNum--;
    queueRenderPage(pageNum);
  };
  
  
  const showNextPage = () =&gt; {
    if (pageNum &gt;= pdfDoc.numPages) {
      return;
    }
    pageNum++;
    queueRenderPage(pageNum);
  };
  
  pdfjsLib
    .getDocument(url)
    .promise.then(pdfDoc_ =&gt; {
      pdfDoc = pdfDoc_;
  
      document.querySelector('#page-count').textContent = pdfDoc.numPages;
  
      renderPage(pageNum);
    })
    .catch(err =&gt; {
     
      const div = document.createElement('div');
      div.className = 'error';
      div.appendChild(document.createTextNode(err.message));
      document.querySelector('body').insertBefore(div, canvas);
     
      document.querySelector('.top-bar').style.display = 'none';
    });
  
  
  document.querySelector('#prev-page').addEventListener('click', showPrevPage);
  document.querySelector('#next-page').addEventListener('click', showNextPage);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="UTF-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge" /&gt;
      &lt;link
        rel="stylesheet"
        href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
        integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
        crossorigin="anonymous"
      /&gt;
      &lt;link rel="stylesheet" href="css/style.css" /&gt;
      &lt;title&gt;PDF Viewer&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="top-bar"&gt;
        &lt;button class="btn" id="prev-page"&gt;
          &lt;i class="fas fa-arrow-circle-left"&gt;&lt;/i&gt; Prev Page
        &lt;/button&gt;
        &lt;button class="btn" id="next-page"&gt;
          Next Page &lt;i class="fas fa-arrow-circle-right"&gt;&lt;/i&gt;
        &lt;/button&gt;
        &lt;span class="page-info"&gt;
          Page &lt;span id="page-num"&gt;&lt;/span&gt; of &lt;span id="page-count"&gt;&lt;/span&gt;
        &lt;/span&gt;
      &lt;/div&gt;
  
      &lt;canvas id="pdf-render"&gt;&lt;/canvas&gt;
  
      &lt;script src="https://mozilla.github.io/pdf.js/build/pdf.js"&gt;&lt;/script&gt;
      &lt;script src="js/main.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>