Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Logical operator "!" not working in ejs file

This is the code

<% if( !title || title!=="login"){   %>   
<div class="dashboard-main-cont">
    <div class="navigation-option">
        <a class="btn btn-primary navbtn" href="/admin/bookings">Booking Requests</a>
        <a class="btn btn-primary navbtn" href="/admin/showprojects">Manage Projects</a>
        <a class="btn btn-primary navbtn" href="#">Calculation Requests</a>
        <a class="btn btn-primary navbtn" href="#">Manage Blogs</a>
        <form action="/admin/logout" method="POST">
            <button class="btn btn-danger">Logout</button>
        </form>
    </div>
<% } %> 

I am not passing a title value but I have put "!" in front of "title", but I am still getting this error:

title is not defined

How to solve this problem? Thanks in advance!!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You probably should define title first using keywords like let or const. This error is coming because you have not defined it.

about 4 years ago · Juan Pablo Isaza Report

0

So, I think that "title" needs to at least be declared for it to be able to work with the "!".

You could render the file by passing title: undefined on the render information. That way, the variable is defined as "undefined", but at least it is defined.

On the snippet below, by defining the variable, it can be used by the bang to detect if it is a "positive" value, as for the second "if", it throws an error.

const declared_title = undefined

console.log("foo")

if( !declared_title || declared_title !== "login") {
    console.log("bar")
}

console.log("fizz")

if( !undeclared_title || undeclared_title !== "login") {
    console.log("buzz")
}

As for the render call, it should look something like this

res.render('your_page',{ title: undefined });

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!