Fernando Souza Fernando Souza - 10 months ago 52
Javascript Question

Javascript boolean parameter not passing correctly

I created a function with various if statements,that will be executed if a parameter is true. But passing false as a parameter doesn't seem to work. What am I doing wrong?

function easySlider(titleP,subTitleP,overlayP){
var title = titleP;
var subTitle = subTitleP;
var overlay = overlayP;

if(title===true) {

if(subTitle===true) {

if(overlay===true) {



You can try this

<div class="sliderTitle"></div>
<div class="sliderSubTitle"></div>
<div class="sliderOverlay"></div>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    function easySlider(title, subTitle , overlay) {
        var titleDisplay     = title ? 'block' : 'none';
        var subTitleDisplay  = subTitle ? 'block' : 'none';
        var overlayDisplay   = overlay ? 'block' : 'none';

        $(".sliderTitle").css("display", titleDisplay);
        $(".sliderSubTitle").css("display", subTitleDisplay);
        $(".sliderOverlay").css("display", overlayDisplay);

    easySlider(false, false, false);