Why in this case the typeof operator() not working?

Hello !

function f(s){
 // document.write(typeof(s)); // ! ! ! ( ( 1 ) ) ! ! !
 var m
 typeof(s) == String ? m = "String" : m = "No, this is not a string"; // ! ! ! ( ( 2 ) ) ! ! ! 
 document.write(m); 
};

f("This is string") // No, this is not a string


Why in this code ! ! ! ( ( 1 ) ) ! ! !, if document.write(typeof(s)); returns string, but when I'm trying to figure out what type of argument ! ! ! ( ( 2 ) ) ! ! !, it triggered the condition - that this argument is not a string? Even if we use the definition of the operator typeof ( ) returns a string indicating the type of the operand in condition ! ! ! ( ( 2 ) ) ! ! ! it turns out that string == String, which in theory should be true? Explain what's going on here?
April 4th 20 at 13:00
4 answers
April 4th 20 at 13:02
Solution
typeof returns a string, not type
typeof("s") == "string" //true
April 4th 20 at 13:04
Solution
typeof returns a string. It is not equal to String
April 4th 20 at 13:06
Peacocks, you say? Heh! (C) the tov. Sukhov.

Well, take do alert(String), will see the output of the function String() { [native code] }. typeof(String) also gives "function".
How is this a quirk of typeof('text') (which will give "string") will be equal to "function"?

"string" != "function", and this regardless of the fact that String without typeof().
April 4th 20 at 13:08
You
typeof(s) == String // String variable??? and in General keywords it is better not to use

then, too, so :
function f(s){
 // document.write(typeof(s)); // ! ! ! ( ( 1 ) ) ! ! !
 var m,
 String = "string"
 typeof(s) === String ? m = "String" : m = "No, this is not a string"; // ! ! ! ( ( 2 ) ) ! ! ! 
 document.write(m); 
};
String is a built — in object constructor strings - violette_Schinner75 commented on April 4th 20 at 13:11
@violette_Schinner75about String // String variable??? was the banter... and further assigning it :) - broderick.Altenwer commented on April 4th 20 at 13:14

Find more questions by tags JavaScript