Preheat your oven to 350°F (175°C).
In a mixing bowl, combine flour, baking soda, cinnamon, and salt.
In another bowl, beat together the butter, brown sugar, and granulated sugar until creamy.
Add the egg and vanilla extract to the butter mixture and mix well.
Gradually add the dry ingredients to the wet ingredients, mixing until just combined.
Fold in the grated carrots and walnuts (if using).
Drop spoonfuls of dough onto a baking sheet lined with parchment paper.
Bake for 12 minutes or until the edges are golden brown.
Allow cookies to cool on the baking sheet for a few minutes before transferring to a wire rack to cool completely.