You can use typeof
operator:
var booleanValue = true; var numericalValue = 354; var stringValue = "This is a String"; var stringObject = new String( "This is a String Object" ); alert(typeof booleanValue) // displays "boolean" alert(typeof numericalValue) // displays "number" alert(typeof stringValue) // displays "string" alert(typeof stringObject) // displays "object"
Example from this webpage. (Example was slightly modified though).
This won’t work as expected in the case of strings created with new String()
, but this is seldom used and recommended against[1][2]. See the other answers for how to handle these, if you so desire.
- The Google JavaScript Style Guide says to never use primitive object wrappers.
- Douglas Crockford recommended that primitive object wrappers be deprecated.
Related Posts:
- How to check whether a string contains a substring in JavaScript?
- Check if a string has a certain piece of text [duplicate]
- How to convert a string to an integer in JavaScript?
- How can I do string interpolation in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- Creating multiline strings in JavaScript
- Creating multiline strings in JavaScript
- Split string into array
- How do you reverse a string in-place in JavaScript?
- What is the correct way to check for string equality in JavaScript?
- Check if a variable is a string in JavaScript
- What’s the best way to convert a number to a string in JavaScript?
- How can I remove a character from a string using JavaScript?
- How to print elements from array with javascript
- How to remove text from a string?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- Delete first character of a string in Javascript
- ES6: Create Strings using Template Literals – Freecodecamp
- How do I check if string contains substring? [duplicate]
- How do I check if string contains substring?
- How can I get the last character in a string?
- How can I get the last character in a string?
- Count the number of occurrences of a character in a string in Javascript
- Converting an object to a string
- Anagrams finder in javascript
- How to interpolate variables in strings in JavaScript, without concatenation?
- How can I extract a number from a string in JavaScript?
- String.Format not work in TypeScript
- How to do case insensitive string comparison?
- How to remove part of a string?
- Escaping HTML strings with jQuery
- Replace all spaces in a string with ‘+’
- How to count string occurrence in string?
- Insert a string at a specific index
- Strip HTML from Text JavaScript
- Strip all non-numeric characters from string in JavaScript
- Wildcard string comparison in Javascript
- Replace spaces with dashes and make all letters lower-case
- Check if a JavaScript string is a URL
- Define a global variable in a JavaScript function
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Cross-Origin Read Blocking (CORB)
- How can I remove a specific item from an array?
- How can I create a two dimensional array in JavaScript?
- How can I refresh a page with jQuery?
- How can I create a two dimensional array in JavaScript?
- Does JavaScript pass by reference?
- ajax jquery simple get request
- Generate random string/characters in JavaScript
- How to resolve TypeError: Cannot convert undefined or null to object
- What is prevState in ReactJS? [duplicate]
- React with ES7: Uncaught TypeError: Cannot read property ‘state’ of undefined
- What’s the source of Error: getaddrinfo EAI_AGAIN?
- How can I guarantee that my enums definition doesn’t change in JavaScript?
- How to write an inline IF statement in JavaScript?
- ‘setInterval’ vs ‘setTimeout’
- Convert string to Title Case with JavaScript
- How to remove item from array by value?
- SecurityError: Blocked a frame with origin from accessing a cross-origin frame
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- Is JavaScript supported in an email message?
- Basic Ajax send/receive with node.js
- onClick to get the ID of the clicked button
- HTML text input allow only numeric input
- How to change the buttons text using javascript
- Can you write nested functions in JavaScript?
- How to use jQuery in chrome extension?
- How do I use this JavaScript variable in HTML?
- How to check if a variable is not null?
- Seeding the random number generator in Javascript
- Bootstrap popover is not working
- Sort array of objects by single key with date value
- How to add a tooltip to an svg graphic?
- How do I make a discord bot join a voice channel?
- How to display raw JSON data on a HTML page
- Getting a random value from a JavaScript array
- Moment Js UTC to Local Time
- Get the size of the screen, current web page and browser window
- Separating html and JavaScript in Flask [duplicate]
- How to read and write into file using JavaScript?
- How to use aria-expanded=”true” to change a css property
- How do I concatenate a string with a variable?
- setTimeout callback argument
- Nonce retrieved from the REST API is invalid and different from nonce generated in wp_localize_script
- conditional layout based on if Innerblocks is not empty
- Only loads on the contact template page
- Min And Max Date With Date Format In Elementor Form Not Working
- How can I use CKEditor with WordPress and let clients edit the content?
- esc_js() breaks unicode sequences by removing the slash ‘\’ character
- Gutenberg getBlockIndex in save() function
- Widgets and Post/Page edit/new blank, console errors only, no server errors
- Why does a on Comment edit page submit the page?
- Custom JS text area in customizer is being formatted wrong in document
- TinyMCE Javascript URL Question
- how to prevent added meta box from being injected with style=”position: fixed; top: 56px;” at scroll down
- How do i load javascript on a specific custom post template via functions.php?
- How to use value from modal tinymce windowManager?
- early enqueueing javascript file in page template, not in functions.php
- Wysiwyg editor not working on 4.2.2