Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if variable is object

let myObject = {
	firstname: 'harry',
  	lastname: 'potter'
}
//check the typeof if, boolean, object, string etc...
console.log(typeof myObject);
if(typeof myObject === 'object') {
	console.log('this is object');
}
Comment

javascript check if variable is object

//checks if is object, null val returns false
function isObject(val) {
    if (val === null) { return false;}
    return ( (typeof val === 'function') || (typeof val === 'object') );
}
var person = {"name":"Boby Snark"};
isObject(person);//true
Comment

javascript check if object

typeof yourVariable === 'object' // true if it's an object or if it's NULL.

// if you want to exclude NULL
typeof yourVariable === 'object' && yourVariable !== null
Comment

check whether an object is a function?

function someFunction() {
  // function body
}
console.log(typeof someFunction);

output =>
function
Comment

PREVIOUS NEXT
Code Example
Javascript :: appTsConfig.compilerOptions[option] = value; 
Javascript :: math floor javascript null 
Javascript :: javascript tan 
Javascript :: ngx paypa remove credit card 
Javascript :: node exec child_process ssh command password 
Javascript :: rafraichir page javascript 
Javascript :: npm i react query 
Javascript :: scroll to bottom of a div 
Javascript :: loopback user password setter overwrite 
Javascript :: string contains in react 
Javascript :: form serialize to json 
Javascript :: jQuery get values of selected checkboxes 
Javascript :: focus input field in modal 
Javascript :: regex replace cpf 
Javascript :: does json only support ascii 
Javascript :: webpack-bundle-analyzer no stats.json file 
Javascript :: mandelbrot set javascript 
Javascript :: how to add keyframe in emotion stled 
Javascript :: javascript stringify an object 
Javascript :: split a string every n characters javascript 
Javascript :: how to use hover functionality using Jquery 
Javascript :: js copy a div 
Javascript :: faker npm 
Javascript :: sort an array by characters length in js 
Javascript :: react native flatlist pull to refresh 
Javascript :: sequelize find one 
Javascript :: javascript get child by name 
Javascript :: jquery add td to tr dynamically 
Javascript :: react native button 
Javascript :: change text of span js html 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =