Javascript logical elements emulator