An optical sensor and an electronic device having an optical sensor. The optical sensor includes: an optical waveguide containing a photochromic material; a light emitter that emits visible light to be incident on the optical waveguide; and a light receiver that detects the visible light emitted from the light emitter and progressing through the optical waveguide. A transmittance of the optical waveguide in relation to the visible light may be changed by the photochromic material as the optical waveguide is exposed to UV light. The optical sensor and the electronic device having the same may be variously implemented according to exemplary embodiments.