HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / TypeScript / TypeScript Logical Operators

TypeScript Logical Operators

TypeScript logical operators are similar what you learn in JavaScript logical operators. These operators help in comparing boolean expressions and producing single boolean value as result.

Logical Operators

OperatorDescription
Logical AND operator – && If both operands (or expressions) are true, then result will be true, else false.

			let firstVar = true;
			let secondVar = false;

			console.log( firstVar && secondVar );	//false
			console.log( firstVar && true );		//true
			console.log( firstVar && 10 );			//10 which is also 'true'
			console.log( firstVar && '10' );		//'10'	which is also 'true'
			

Read More: Truthy and Falsy

Logical OR operator – || If any of the two operands (or expressions) are true, then result will be true, else false.

			let firstVar = true;
			let secondVar = false;

			console.log( firstVar || secondVar );	//true
			console.log( firstVar || true );		//true
			console.log( firstVar || 10 );			//true
			console.log( firstVar || '10' );		//true
			
Logical NOT operator – ! It is used to reverse the logical state of its operand. It converts true to false, and vice-versa.

			let firstVar = 10;
			let secondVar = 20;

			console.log( !true );		//false
			console.log( !false );		//true
			console.log( !firstVar );	//false
			console.log( !null );		//true
			

Drop me your questions in comments section.

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Comments are closed on this article!

Search Tutorials

TypeScript Tutorial

  • TypeScript – Introduction
  • TypeScript – Types
  • TypeScript – Union Types
  • TypeScript – String Literal Types
  • TypeScript – var, let and const
  • TypeScript – Template Strings
  • TypeScript – Arithmetic Operators
  • TypeScript – Logical Operators
  • TypeScript – Comparison Operators
  • TypeScript – ‘for…of’ Loop
  • TypeScript – Spread Operator
  • TypeScript – Arrays
  • TypeScript – Enums
  • TypeScript – Map
  • TypeScript – Set
  • TypeScript – Functions
  • TypeScript – Function Overloading
  • TypeScript – Transpiler
  • TypeScript – Truthy and falsy
  • TypeScript – == vs ===
  • TypeScript – undefined vs null
  • TypeScript – Variable Hoisting
  • TypeScript – tsconfig.json

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Sealed Classes and Interfaces