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?
- What’s the best way to convert a number to a string in JavaScript?
- Check if a variable is 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
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- How do I redirect to another webpage?
- Invariant Violation: Objects are not valid as a React child
- How can I merge properties of two JavaScript objects dynamically?
- Infinite Scrolling in Asp.Net MVC with jQuery / AJAX Issues
- What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})
- Getting “TypeError: failed to fetch” when the request hasn’t actually failed
- How can I print using JQuery
- Short circuit Array.forEach like calling break
- TypeError: Router.use() requires middleware function but got a Object
- MissingSchemaError: Schema hasn’t been registered for model “User”
- classical inheritance vs prototypal inheritance in javascript
- Uncaught TypeError: Cannot read property ‘value’ of null
- How to subtract date/time in JavaScript?
- Async/await in componentDidMount to load in correct order
- Dynamically load JS inside JS
- Tainted canvases may not be exported
- How to sort an object array by date property?
- React router not showing browser history
- How to define DO NOTHING in JavaScript
- How to get the difference between two arrays in JavaScript?
- What happened to Lodash _.pluck?
- Simplest/cleanest way to implement a singleton in JavaScript
- What counts as CPU Intensive tasks (eg. sorting, searching etc?)
- HTML make text clickable without making it a hyperlink
- Uncaught ReferenceError: React is not defined
- How to get the browser viewport dimensions?
- Getting HTML form values
- jQuery checkbox checked state changed event
- Javascript, viewing [object HTMLInputElement]
- Why onbeforeunload event is not firing
- etect the Enter key in a text input field
- Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (
) - Include Javascript as Plain (No file inclusion)
- Insert shortcode in post editor from javascript (Visual / HTML)
- Block editor: How to check if block editor has initialized and populated the data store?
- Contact Form 7 – Give each checkbox a class?
- is_page not working when loading javascript with add_action in functions.php
- Detect When User Reads Full Article? [closed]
- How to set callback to execute after all the tinyMCE editors have been initialized?
- How to add classes and events to image in javascript using Gutenberg?
- Javascript in wordpress
- How to inherit custom javascript from parent to child pages?
- imporing HTML+javascript from REST API
- how to add a custom javascript file to our theme
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- WordPress Guternberg Content For React Native
- Custom block update rendering when reused
- How do I add my own scripts to the add_action(‘wp_enqueue_scripts’) function?
- Post title and url not showing on google map marker [closed]
- Including js script at end of header
- contact form 7 javascript and wpcf7_before_send_mail action
- Embed Kajabi into WP
- Uncaught SyntaxError: missing ) after argument list [duplicate]
- Styling parent based on a child element of a child in a WordPress page
- I have custom html mixed with inline javascript that I want added to my WordPress site, how do I achieve this?
- How to update the input[type=number] quantity field using custom buttons?
- Why isn’t my SVG path rotating on scroll on iPhones?
- Working with a non-React external library in a custom block
- Using a form to pass GET parameters and create an array of posts accordingly