Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Boolean 3/4 | Data Types and Variables
Introduction to JavaScript

book
Boolean 3/4

The Boolean() Function:

The Boolean() function, in JavaScript, is used to return or convert a value to its Boolean value i.e., true or false.

Almost any value is evaluated as true if it has some sort of content, for example.

let name="paul";
console.log(Boolean(name));
12
let name="paul"; console.log(Boolean(name));
copy

As you can see for the above variable, name we get the output as true because it had a string value. An empty string would have given a false output.

Oppgave

Swipe to start coding

Use the Boolean method to check wheater the value given to the variable emptyString is true or false. Show the answer on the console.

Løsning

let emptyString="";
console.log(Boolean(emptyString));

As you can see now for an empty string it gave the output as false.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 17
single

single

let emptyString="";

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt