In a word? Cost.
What you’re seeing is a power supply/power adaptor, and it does various things like change the current from AC to DC, and some monitor/regulate the voltage and amperage, contain capacitors, things like that. They do a variety of functions.
Higher quality power supplies (laptops, game consoles, etc.) have a “brick” further down the cord, while the cheaper ones put it right there on the plug, making it inconvienent as hell. Cost is a factor in manufacturing, so they cut corners wherever they can.
Latest Answers