Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

Sean Fallon
Sean Fallon
8,516 Points

I don't understand the () that are all alone. Something about arrow function syntax doesn't make sense to me.

button.addEventListener( 'click', () => {
  p.textContent = input.value + ':';
})

Is there a video that explains this layout? A little better or maybe someone can link something that explains this style. I don't understand the ':' or the parenthesis by themselves. Actually most of this isn't clicking. Thank you so much.

1 Answer

Sean Fallon

I'll take a stab at answering this, and hopefully it is helpful. Along with my explanation I would also recommend checking out https://www.w3schools.com/Js/js_arrow_function.asp.

In your example () => is the arrow function syntax, and I really think it's just something to memorize if you want to use arrow functions moving forward. When you create a function I do know that it that requires the open parenthesis (). They can hold a value to pass into the function, or it can be empty like in the example you provided. Personally, I find arrow functions more difficult to read than the standard way to write a function, but I'm still getting used to all this as well. In regards to ':' that was added to include : after the input.value. A reference for this can be found https://teamtreehouse.com/library/combine-strings

button.addEventListener( 'click', () => { p.textContent = input.value + ':'; })
Sean Fallon
Sean Fallon
8,516 Points

Thank you for the help!