Test your JavaScript Skills:Fundamentals-1

Part 1

Introduction

Namaste, In this blog post I will discuss 7 common FAQs on JS Fundamentals

Video Tutorial

  1. Identify the output of the below program

     let mydata = "data" / 2;
     console.log("mydata", mydata);
    

    a. Error

    b. data

    c. undefined

    d. NaN

    Answer: d

    Reason: The string is coerced into a number which is NaN and the division of NaN is NaN.

  2. Identify the output of the below program

     let mydata = "data" / 2;
     console.log("type", typeof mydata);
    

    a. number

    b. string

    c. undefined

    d. Error

    Answer: a

    Reason: NaN is a number type

  3. Identify the output of the below program

     let mydata = true/false;
     console.log("mydata", mydata);
    

    a. 1

    b. 0

    c. Infinity

    d. Error

    Answer: c

    Reason: The true is coerced to 1 and the false to 0. Hence the division of 1/0 is

    Infinity in Javascript.

  4. Identify the output of the below program

     console.log(typeof boolean, typeof  number, typeof string);
    

    a. boolean, number, string

    b. null, null, null

    c. Error

    d. undefined, undefined, undefined

    Answer: d

    Reason: The boolean, number and string are not primitives. They are also not declared and hence undefined for all.

  5. Identify the output of the below program

     console.log(typeof Infinity, typeof NaN);
    

    a. Error

    b. number, number

    c. undefined, undefined

    d. null, null

    Answer: b

    Reason: Infinity and NaN are number types.

  6. Identify the output of the below program

     let mydata= 100n
     console.log(typeof mydata, mydata);
    

    a. number, 100

    b. string, 100n

    c. bigint, 100n

    d. Error

    Answer: c

    Reason: Integer values suffixed with n is identified as bigint.

  7. Identify the output of the below program

     console.log(typeof typeof);
    

    a. number

    b. string

    c. undefined

    d. Error

    Answer: d

    Reason: Since typeof is an operator and the operand passed to it is also typeof, it is considered an invalid operand (because is it pre-defined).

Video Tutorial

Did you find this article valuable?

Support Programming with Mahavir by becoming a sponsor. Any amount is appreciated!