How to check if a variable is a string in Node.js

2 Answers

0 votes
const value = 'nodejs';

if (typeof value === 'string' || value instanceof String) {
  	console.log('string');
} else {
  	console.log('not string');
}

  
  
  
  
/*
run:
  
string
  
*/

 



answered May 26, 2022 by avibootz
0 votes
console.log(typeof ""); 
console.log(typeof "nodejs"); 
console.log(typeof "99"); 
  
  
  
  
/*
run:
  
string
string
string
  
*/

 



answered May 26, 2022 by avibootz

Related questions

1 answer 111 views
1 answer 164 views
1 answer 117 views
1 answer 176 views
1 answer 142 views
...