Declaring String Variables

Your first JavaScript task is to create string variables for each of the data attributes you added to the markup. (If those are unfamiliar terms, do not worry – we will explain in just a moment.)

At the top of main.js, start by adding a variable named DETAIL_IMAGE_SELECTOR and assigning it the string '[data-image-role="target"]'.

var DETAIL_IMAGE_SELECTOR = '[data-image-role="target"]';

This might not be much code, but it is worth a closer look. Let’s start in the middle, with the = symbol. This is the assignment operator. Unlike in mathematics, the = symbol in JavaScript does not mean that two things are equal. Instead, it means “Take the value on the righthand side and give it the name on the lefthand ...

Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.