Sunday, 06 September 2026
Advertisement Advertise Your advert could be here Reach thousands of learners and ICT professionals across Rwanda. Contact us
Advertisement Opportunity Jobs, scholarships & hackathons Fresh openings from Rwandan job boards are pulled in every hour. See openings

Data types and operators

JavaScript basics · lesson 3 of 10

In this lesson: Recognise each type and compare values safely.

The primitive types

const text    = 'Hello';        // string
const count   = 42;             // number  (integers and decimals both)
const ready   = true;           // boolean
const nothing = null;           // deliberately empty
let   unset;                    // undefined — declared but never given a value

Note there is no separate integer type. 10 and 10.5 are both number.

Checking a type

typeof 'hello'   // 'string'
typeof 42        // 'number'
typeof true      // 'boolean'
typeof undefined // 'undefined'
typeof {}        // 'object'
typeof []        // 'object'  ← arrays are objects
typeof null      // 'object'  ← a famous historical bug in the language

Arithmetic

10 + 3    // 13
10 - 3    // 7
10 * 3    // 30
10 / 3    // 3.333...
10 % 3    // 1   remainder
10 ** 3   // 1000 power

Strings

const first = 'Aline';
const last  = 'Uwase';

// Template literals — backticks, with ${} for values
const full = `${first} ${last}`;      // 'Aline Uwase'

full.length          // 11
full.toUpperCase()   // 'ALINE UWASE'
full.includes('Uwa') // true
full.split(' ')      // ['Aline', 'Uwase']
'  padded  '.trim()  // 'padded'

Comparison — and the one rule that saves you

5 === 5      // true   same value AND same type
5 === '5'    // false  number vs string
5 == '5'     // true   == converts first — avoid it
5 !== '5'    // true

10 > 5       // true
10 >= 10     // true
Always use === and !==. The loose == converts types before comparing, which produces genuinely bizarre results ('' == 0 is true, null == undefined is true). Strict comparison has no surprises.

Logical operators

true && false   // false — AND, both must be true
true || false   // true  — OR, either will do
!true           // false — NOT

Truthy and falsy

In a condition, every value counts as either true or false. These six are falsy:

false, 0, '' (empty string), null, undefined, NaN

Everything else is truthy — including '0', 'false' and [].

Create a free account to save progress

All lessons in this track

  1. 1
  2. 2
  3. 3
  4. 4
    Conditions: if, else and switch ~25 min account needed
  5. 5
    Loops ~25 min account needed
  6. 6
    Functions ~30 min account needed
  7. 7
    Arrays and array methods ~30 min account needed
  8. 8
    Objects ~25 min account needed
  9. 9
    The DOM: changing the page ~30 min account needed
  10. 10
    Events ~25 min account needed
Advertisement Yanjye Learn a new digital skill this week ICT, programming and professional courses with graded weekly assignments. Start free