The quantification and electrochemical behavior of methyldopa in tablet and urine samples were carried out using a glassy carbon electrode modified with double-charged ionic liquid and a layered double hydroxide. Magnesium aluminum layered double hydroxides/double charged diazabicyclo [2.2.2] octane ionic liquid (Mg/Al LDH/DABCO-IL) was prepared and immobilized on a glassy carbon electrode. The results of Fourier transform infrared spectroscopy (FT-IR) and X-ray diffraction (XRD) demonstrated that Mg/Al LDH/DABCO-IL was successfully synthesized. The cyclic voltammogram of methyldopa on the modified electrode exhibited a well-defined anodic peak at 0.63 V in 0.1 M of ammonia buffer. The experimental parameters were optimized and the kinetic parameters were investigated. Under the optimized conditions, the fabricated modified electrode exhibited excellent performance in the linear range of 0.23-860 μM with a correlation coefficient of 0.9959. The detection limit was 0.076 μM (S/N = 3). The fabricated electrode showed good reproducibility, stability, and selectivity properties. The method was successfully applied for the determination of methyldopa in pharmaceutical and urine samples.