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

144
Views
creating review carousel from medium.io website
var itemClassName = "carousel__photo";
    items = d.getElementsByClassName(itemClassName),
    totalItems = items.length,
    slide = 0,
    moving = true;

I saw this part of the code on the medium.com website while creating a review carousel. how did they declare this variable? I can not understand this declaration and they use d instead of document how? and why? I am a beginner... if you need more information kindly visit medium.com site .bcuz of your clarity I added only the part I got confused

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That article has used IIFE JavaScript functions. you could read more about that concept from the link that original article said or from any other tutorial like this one. simply it is a way of running a function without need to call it in your code. for better understanding I converted the script of original article to a normal function.

this is the article code:

(function(d)
    { 
        var itemClassName = "carousel__photo";
        items = d.getElementsByClassName(itemClassName),
        totalItems = items.length,
        slide = 0,
        moving = true;

        console.log(itemClassName);
    })
(document);

And this is the code I converted:

let documentVar = document;
function carousel(documentArgu) {
    var itemClassName = "carousel__photo2";
        items = documentArgu.getElementsByClassName(itemClassName),
        totalItems = items.length,
        slide = 0,
        moving = true;

        console.log(itemClassName);
}

carousel(documentVar)

In the converted version you need to call carousel(documentVar) function to run it. But in the article code you do not need to call function. using IIFE has other advantages also that you can read more from tutorials. But about your question that why d stands for document, the reason is that you could pass IIFE function arguments in the last parenthesis and that means the argument d used in function(d) is the same document that was defined in (document) in the last of article code.

about 4 years ago · Juan Pablo Isaza Report
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!