Carbon nanotubes (CNTs) are 1D nanostructures with unique properties that recommend them for applications in future nanoelectronics and optoelectronics. I will discuss the electronic structure and electrical properties of semiconducting carbon nanotubes and the fabrication and performance of nanotube devices. Transport experiments and simulations will be used to determine the switching mechanism of nanotube transistors, the nanotube-metal interactions and the role of the ambient environment on the transistor properties. I will then discuss how these findings can be utilized to produce high performance p-, n- and ambipolar nanotube field-effect transistors (CNTFETs) and logic circuits. Semiconducting CNTs are direct gap materials. This, plus their 1D character have important implications for their optical properties. I will first discuss the nature of the excited states of CNTs. I will show that CNTs form strongly bound 1D-exciton states and discuss the scaling properties of these excitons. Spectra obtained by recording the photocurrent of single CNTs employed as channels of CNTFETs will be presented. I will then show that an ambipolar nanotube field-effect transistor can act as a single molecule, electrically-driven light source. The spectra, polarization and the dependence of the light intensity on applied bias will be used to prove that the light is generated through radiative e-h recombination in the CNT. Spatially-resolved studies of the emission as a function of applied bias will be used to map the boundaries of the electron and hole currents and to determine the recombination lengths. These results show that a CNTFET is a particularly versatile molecular device that can be used, depending on the bias conditions, as a high performance electrical switch, a light detector or a light source.