Answers for "check if variable is object or string js"

12

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');
}
Posted by: Guest on May-09-2020
1

javascript check if object is string

if (typeof myVar === 'string' || myVar instanceof String)
// it's a string
else
// it's something else
Posted by: Guest on September-15-2021

Code answers related to "check if variable is object or string js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language