@stdlib/assert-is-same-type
v0.2.2
Published
Test if two arguments have the same type.
Downloads
4
Readme
isSameType
Test if two arguments have the same type.
Installation
npm install @stdlib/assert-is-same-type
Usage
var isSameType = require( '@stdlib/assert-is-same-type' );
isSameType( a, b )
Tests if two arguments a
and b
have the same type.
var bool = isSameType( false, true );
// returns true
bool = isSameType( 'beep', 'boop' );
// returns true
bool = isSameType( 0.0, '0.0' );
// returns false
Notes
- The function uses the
typeof
operator to determine the type of each argument. - The function returns
true
if the types are the same andfalse
otherwise.
Examples
var isSameType = require( '@stdlib/assert-is-same-type' );
var bool = isSameType( true, false );
// returns true
bool = isSameType( 3.14, -3.14 );
// returns true
bool = isSameType( {}, [] );
// returns true
bool = isSameType( null, null );
// returns true
bool = isSameType( NaN, NaN );
// returns true
bool = isSameType( null, NaN );
// returns false
bool = isSameType( 0.0, '0.0' );
// returns false
See Also
@stdlib/assert-is-same-native-class
: test if two arguments have the same native class.@stdlib/assert-is-same-value
: test if two arguments are the same value.@stdlib/assert-is-strict-equal
: test if two arguments are strictly equal.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.