devxlogo

JavaScript Variable Declaration

JavaScript Variable Declaration

Question:
I am new to JavaScript, but familiar with a variety of other languages. I don’t quite understand what the following variable declarations do:

ns4 = (document.layers)? true:falseie4 = (document.all)? true:false

Is it just setting up a boolean variable?

Answer:
Yes, those are just boolean values.

This is the same thing as saying:

if (document.layers) {    ns4 = true}else {    ns4 = false}

However, keep in mind that the next version of Netscape won’t support document.layers or document.all, so both of these fields will be set to false.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist