0
Q:

typeof javascript

 What value it has 	 			What the output shows you 
 						when you write |console.log(typeof(variable);
Undefined:						"undefined"
Null:							"object"
Boolean:						"boolean"
Number:							"number"
String:							"string"
Function object:				"function"
E4X XML object:					"xml"
E4X XMLList object:				"xml"
NodeList						"Nodelist [more data]"
HTMLCollection					"HTMLCollection(1) [more data]"
2
// get type of variable

var number = 1
var string = 'hello world'
var dict = {a: 1, b: 2, c: 3}

console.log(typeof number) // number
console.log(typeof string) // string
console.log(typeof dict)   // object
2
//typeof() will return the type of value in it's parameters.
//some examples of types: undefined, NaN, number, string, object, array

//example of a practical usage
if (typeof(value) !== "undefined") {//asuming value is already set
  	//execute code
}
8
console.log(typeof 93);
// Output = "number"

console.log(typeof 'Maximum');
// Output = 'string'

console.log(typeof false);
// Output = "boolean"

console.log(typeof anUndeclaredVariable);
// Output = "undefined"
3
typeof("iAmAString");//This should return 'string'
//NO camelCase, as it is a JS Keyword
4
// C# program to illustrate the 
// concept of typeof operator 
using System; 
  
class GFG { 
  
    // Here store Type as a field 
    static Type a = typeof(double); 
  
    // Main method 
    static void Main() 
    { 
  
        // Display the type of a 
        Console.WriteLine(a); 
  
        // Display the value type 
        Console.WriteLine(typeof(int)); 
  
        // Display the class type 
        Console.WriteLine(typeof(Array)); 
  
        // Display the value type 
        Console.WriteLine(typeof(char)); 
  
        // Display the array reference type 
        Console.WriteLine(typeof(int[])); 
    } 
} 
0
console.log(typeof 'blubber');
3
var x = "Hello World";
typeof x; // "string"
1
//retourne le type de la variable

let number = 1;
let string = "bonjour";
let bool = true;
let dict = { a: 1, b:2 };

console.log(typeof(number));//renvoie Number
console.log(typeof(string));//renvoie String
console.log(typeof(bool));//renvoie Boolean
console.log(typeof(dict));//renvoie Object

//cas spécial

console.log(typeof(NaN));//NaN = Not A Number renvoie Number
0

New to Communities?

Join the community