ACs work in a similar way to fridges: they use a compressor to sequentially compress and expand gas in a refrigerating coil. The unit sucks in the air in the room, humidity condenses on the coil and accumulates in a tank as liquid. At the same time the AC ejects air previously cooled by the same refrigerating coil.
They need an outlet facing outside because, in order to function, their compressor necessarily generates heat, which must be directed away from the location to refrigerate.
Latest Answers