Private Eye 30/30


#1

Can someone please explain what the !== "function" bit means in the code below?

for(var x in myStudentReport) {
if(typeof myStudentReport[x] !== "function") {
console.log("Muahaha! " + myStudentReport[x]);
}
Does it mean that it is checking to see if it is a function? or if it has a this. keyword? and if so it will make it public?

thanks in anticipation


#2

@missmuffett Yes, I believe so.... Well to be more accurate, checking to make sure it is not a function. (Unsure what "it" in "make it public" is referring to however.) @factoradic addressed the same question for me in detail here.


#3

@missmuffett
Have a read in
== the Book ==
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
and the !== is called Non-identity / strict inequality (!==) operator
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators


#4

THank you very much - I appreciate your help with this! I understand now.


#5

Thank you very much for your help - this was most helpful.


#6

My working exercise:

function StudentReport() {
    var grade1 = 4;
    var grade2 = 2;
    var grade3 = 1;
    this.getGPA = function() {
        return (grade1 + grade2 + grade3) / 3;
    };
}

var myStudentReport = new StudentReport();

for(var x in myStudentReport) {
    if(typeof myStudentReport[x] !== "function") {
        console.log("Muahaha! " + myStudentReport[x]);
    }
}

console.log("Your overall GPA is " + myStudentReport.getGPA());

#7

@datasolver35832, that is exactly how I did it as well.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.