answersLogoWhite

0


Best Answer

Like this:

if (condition) {

statements;

}

"statements" may be a single Java statement, or lots of them. In theory you can omit the braces if there is only a single statement; however, the recommended practice is to always include them.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

var x = 0;

if(x == 0){

return true;

}else{

return false;

}

You can use many diffrent operators inside the if statment, some examples:

if(x >= 0), if X is greater or equal to zero.

if(x == 0), if X is equal to zero.

if(x > 0 & y <= 0), if X is greater than zero and (&) Y is less or equal to zero.

if(x > 0 | y <= 0), if X is greater than zero or (|) Y is less or equal to zero.

if(x != y), if X not equals Y.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to write an if statement in javascript?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a javascript?

go to notepad and write Javascript code and save it as .js and then import it into a page with a src tag


How do you write HTML codes and javascript events together in your HTML kit?

You need to write the HTML code in the tag format. If you want to write JavaScript put it in &lt;script&gt; tag.


How to use Javascript to write to the local filesystem?

For security reasons, regular JavaScript scripts in web pages are not allowed to write to the local file system.


What languages can you write a Google Apps script on?

JavaScript


What symbol is used to indicate the end of each JavaScript statement?

The semi-colon ( ; ) is used to indicate the end of a statement in JavaScirpt.


What are non-executable statement in a program javascript?

Comments are non-executable statements within JavaScript (or any other programming.) In JavaScript, comments are surrounded by /* and */ for multi-line comments, or started with // for single line comments.


What is a JavaScript statement?

A statement in a programming language is a standalone unit of code. In JavaScript, statements generally end with a semicolon or a closing bracket.Examples:// variable statementvar x = 5;// if statementif (x == 0) {...}The ECMAScript language specification lists all the different types of statements permitted in JavaScript. See related links.


Where do you write javascript?

JavaScript is written in an HTML document. You start it with this tag:and end it with:


What are good Java script codes?

depending on the intention of the javascript codes you wish to write. there is much you can do with javascript but the only way to find out what "good Java script codes" are is to explore what you want the Javascript to do on the page.


What is the difference between Javascript and Jquery?

JavaScript is a scripting language that is mainly used within a web browser. Jquery is a library of javascript code that can be used together with your javascript program. A set of functions that can preform common tasks is provided, which will reduce the amount of code that you have to write yourself.


What is the correct JavaScript syntax to write Hello World?

document.write("hello world");


How does write statement differ from writeln statement?

I think you mean written statement. What you are asking about write statement you are confusing with written statement, the same with write in statement. A written statement is simply putting your words, or your version of events in writing.