Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS Sass Basics Add Reusable Logic to Your Sass Smarter Mixins with null and Keyword Arguments

With mixins and nulls, Why wouldn't you just delete the variable instead of giving it a null value?

The video explains if you don't assigned a value to a variable in a mixin, it will give you an error message. Then by assigning a unnecessary none value, it will assigned that for each instance. But why would you use null? Why not just delete the variable unless you specifically were trying to remove a border which, you could probably avoid by not assigning it a border in the first place?

Maybe i'm way off or missing something.

2 Answers

Samuel Kleos
Samuel Kleos
Front End Web Development Techdegree Student 7,604 Points

The reason you don't delete the parameter is that you want to be able to pass border values as an argument for your mixin at some point, but perhaps not all the time.

In situations when you pass the argument 'none' for the parameter where you don't need it, you get a line of code that is not needed with a rule (or perhaps) multiple rules with a value of none.

We don't want that, so we give it a default value of null. Which means if you don't pass an argument for it, you don't get an error, and the CSS that would normally have been generated as a result of that parameter won't be generated.

If you have a mixin that sometimes you want to add a border and sometimes you don't, being able to pass null allows you that option without having to write a mixin for every eventuality.

Hope that makes sense, good luck! :)