0% found this document useful (0 votes)
4 views3 pages

C++ To JavaScript Cheatsheet

This document is a cheatsheet comparing C++ and JavaScript syntax across various programming constructs including variable declaration, if-else statements, for loops, functions, arrays, classes, and file handling. It provides equivalent code snippets for each construct in both languages. The cheatsheet serves as a quick reference for developers transitioning from C++ to JavaScript.

Uploaded by

amitesh3168
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

C++ To JavaScript Cheatsheet

This document is a cheatsheet comparing C++ and JavaScript syntax across various programming constructs including variable declaration, if-else statements, for loops, functions, arrays, classes, and file handling. It provides equivalent code snippets for each construct in both languages. The cheatsheet serves as a quick reference for developers transitioning from C++ to JavaScript.

Uploaded by

amitesh3168
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C++ to JavaScript Cheatsheet

1. Variable Declaration

C++:

int x = 10;

float y = 5.5;

char z = 'A';

JavaScript:

let x = 10;

let y = 5.5;

let z = 'A';

2. If-Else Statement

C++:

if (x > 0) {

cout << "Positive";

} else {

cout << "Negative or zero";

JavaScript:

if (x > 0) {

[Link]("Positive");

} else {

[Link]("Negative or zero");

3. For Loop

C++:

for (int i = 0; i < 5; i++) {

cout << i;

}
JavaScript:

for (let i = 0; i < 5; i++) {

[Link](i);

4. Functions

C++:

int add(int a, int b) {

return a + b;

JavaScript:

function add(a, b) {

return a + b;

Or using arrow function:

const add = (a, b) => a + b;

5. Arrays

C++:

int arr[3] = {1, 2, 3};

JavaScript:

let arr = [1, 2, 3];

6. Classes and Objects

C++:

class Person {

public:

string name;

int age;

void greet() {

cout << "Hello " << name;


}

};

JavaScript:

class Person {

constructor(name, age) {

[Link] = name;

[Link] = age;

greet() {

[Link]("Hello " + [Link]);

7. File Handling

C++:

#include <fstream>

ofstream file("[Link]");

file << "Hello world!";

[Link]();

JavaScript ([Link]):

const fs = require('fs');

[Link]('[Link]', 'Hello world!');

You might also like