Which is better when loosing weight and develop muscle?

Less Calories or no sugar? I heard different perceptions about this issue and at the end I dont know who is right or who is wrong or nobody is right or wrong. Trainers and fitness instructors say that in order to loose weight and build muscle at the same time you have to be in a calorie deficit, so I assume you have to consume less calories that what you burn. So here is my confusion, when you buy products, that have less calories but they have sugar and others have no sugar but have calories. So then what is going ot be in this case?

Im not a person who counts calories as Im not in any diet plan or program, I eat everything in moderation but then I always wonder.

I mean if you buy food with less calories then the product may probably have sugar to compensate the lack of calories, but also if you have a total sugar free product, probably it will have calories.
Which is better when loosing weight and develop muscle?
Post Opinion