Apptware Interview Question

Explain the logic behind the Binary Search and write a JavaScript program illustrating the same.