Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda