Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:33:48+00:00 2026-06-07T03:33:48+00:00

The following is common code floating around online that checks if cookies are enabled

  • 0

The following is common code floating around online that checks if cookies are enabled in a particular browser:

var cookieEnabled = (window.navigator.cookieEnabled) ? true : false;

if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
    document.cookie = "testcookie"
    cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false
}

if (!cookieEnabled) {
    // do some work
}

Why are the first and fifth lines ternary statements? Does

var cookieEnabled = (window.navigator.cookieEnabled) ? true : false;

catch some case that the following wouldn’t?

var cookieEnabled = (window.navigator.cookieEnabled);

The same goes for the fifth line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:33:51+00:00Added an answer on June 7, 2026 at 3:33 am

    The ternary statement at the first line is useful in that it coverts a possible non-boolean value into a boolean one. Consider the following code

    window.navigator.cookieEnabled = "evil people do this";
    

    The above is legal and as the value says evil people do do this. Without the ternary statement the following code wouldn’t execute as expected

    if (cookiesEnabled === false) { 
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The MustangPeak Common Library (http://code.google.com/p/mustangpeakcommonlib/) contains the following code that converts a method to
The following simple code pattern is very common in graphics programming. It creates an
I have the following code in python from selenium import webdriver from selenium.webdriver.common.by import
It seems that the following is a common method given in many tutorials on
I have the following Common Lisp code: (defun micro-read-eval-print () (format t Micro >
I inherited 2 JSP projects (tomcat) in my eclipse with common code that is
I have the following code fork()'s 2 children from a common parent and implements
The following Common Lisp code does not produce the output I would expect it
I have the following perl code : use strict; use warnings; use Test::Cmd::Common; my
I have common code that I want in various events for our standard jqGrid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.