Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

type of variable js

// 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
Comment

js get type of variable

typeof variable;
Comment

how to get type of variable in javascript

> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
Comment

javascript get type of var

typeof operando
Comment

js get type


function gettype(data) {
            let itemType = Object.prototype.toString.call(data)
            let type = ''

            switch (itemType) {
                case "[object Null]":
                    type = 'Null';
                    break;

                case "[object Object]":
                    type = 'Object';
                    break;

                case "[object Array]":
                    type = 'Array';
                    break;

                case "[object String]":
                    type = 'String';
                    break;

                case "[object Boolean]":
                    type = 'Boolean';
                    break;

                case "[object Number]":
                    type = 'Number';
                    break;
            }

            return type
        }
Comment

check the type of a variable in js

if(typeof variable == 'object'){
  //
}
Comment

js get type

 Object.prototype.toString.call(data)
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to remove last element of array in javascript 
Javascript :: comment in javascript 
Javascript :: check if value is number 
Javascript :: javascript map 
Javascript :: render react component 
Javascript :: get data from json placeholder 
Javascript :: Start Express Properly 
Javascript :: electron js nodeintegration 
Javascript :: segregate value by _ using jquery like explode 
Javascript :: javascript .firstordefault 
Javascript :: date format date and time in js 
Javascript :: change console log to print javascript 
Javascript :: react native margin vs padding 
Javascript :: javascript array filter elements greater than 
Javascript :: Converting google document to pdf using Scrips 
Javascript :: how to send response to client in nodejs using res object 
Javascript :: react make setstate synchronous 
Javascript :: 1 dollar in rupees 
Javascript :: import firebase auth react 
Javascript :: Uncaught (in promise) cancel 
Javascript :: javascript comparison operators 
Javascript :: javascript selector second element nth child element 
Javascript :: how assign custom date to input type date in javascript 
Javascript :: how can we open page on new tab in angular or js or typescript 
Javascript :: change cwd node 
Javascript :: react load script after render 
Javascript :: react native shadow android 
Javascript :: array flat 
Javascript :: capitalize name function javascript 
Javascript :: react props have changed method 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =