0

I have this function to get cookies values if cookies exist or false if not, but i get undefined

This is my function :

function ifCookieExist(cookieName) {
    session.defaultSession.cookies.get({ name: cookieName })
      .then((cookies) => {
        return cookies[0].value
      }).catch((error) => {
        return false
      })
  }

called here : console.log(ifCookieExist('actualList'));

actual result : undefined expected result : cookies value or false

for info when i use console.log inside function like this :

function ifCookieExist(cookieName) {
    session.defaultSession.cookies.get({ name: cookieName })
      .then((cookies) => {
        console.log(cookies[0].value)
      }).catch((error) => {
        return false
      })
  }

i got expected result in console

Oswald
  • 1
  • 2
  • You never `return` anything from `ifCookieExist` function itself, only from the `then` and `catch` callback functions. – Bergi May 27 '23 at 13:48

0 Answers0